While Calvin's answer is awesome, you may be able to identify the baby's genitalia at an ultra sound.
In the US, OB/GYNs don't usually do ultra sounds between 12 and 20 weeks, and in most cases the genitalia will not be seen at 12 weeks.
At 20 weeks you will be able to see it in most babies, however, some babies are in a position where you cannot see it. Depending on doctor they may not want to spend too long time finding out about it - I believe at 20 weeks you also look for 4 chambers of the heart, kidneys and 2 brain halves, things like that.
In some cases, the doctor (or, in fact, ultra sound technician) think they saw the genitalia, but it was interpreted wrong. You don't know for sure until the baby is born.