The best time to go to the gym depends on your schedule and preference.
Morning: Working out in the morning can boost your metabolism and help you avoid crowds. Some people like getting a workout out of the way before work and say it prepares them physically and mentally and/or helps them sleep better.
Afternoon/evening: You may feel more physically ready to exercise in the afternoon or evening and have less chance of injuring yourself.
The most important thing to do is choose a time of day when you can work out effectively and consistently.