Roosters do not only crow when the sun rises. They have a tendency to crow at the oddest times of day and can be quite loud.
The old folklore "When the rooster crows at midnight"is not at all far-fetched. I have heard my roosters crow on several occasions at midnight. It is also one of the reasons why I sleep with a fan and sound generator next to my bed.
First let me say that if you're living in a heavily populated area you may want to opt out of having a rooster. They are not necessary for egg production.
Why does the rooster crow? The sun rising actually has nothing to do with their crowing. During the winter months I quite often run a light or heat lamp to increase egg production and add a little additional warmth to the roost. The roosters still continue to crow when they feel like it. The crowing is in part a territorial call or warning to other roosters, but I have also noticed that they will crow when I'm a little late feeding them. Basically the crowing is a method of communication and one of many calls or sounds that chickens make. I have also noticed that they have a tendency to crow more if they are cooped up as opposed to being free range.
If you need the rooster for helping to protect the flock or reproduction, then it is one of those things that you are just simply going to have to put up with. Hopefully you live on a large enough plot of land that you can locate the hen house or roost away from your residence or your neighbors residence.
When I look at it, it's part and parcel of living on a homestead and whether it's roosters crowing or coyotes or dogs howling makes little difference. I personally would rather listen to my roosters crow then the busy streets of the city, and give gratitude for being able to live in a rural setting.