Time isn't valid but code works- grand finale


6. Grand Finale

no error messages but this is what prints to the console: 8/27/2016 1:32:4

the time isn't a time. it is 9:30 PM EST btw

Replace this line with your code. 
from datetime import datetime
now = datetime.now()

print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)

why is it doing this???? I get no error messages and it runs fine. Please help


Take a look at documentation -> https://docs.python.org/2/library/datetime.html#datetime.datetime.now

datetime.now returns local time. This code is not executed by your computer, but by the codecademy server. That is why the time is not the same as on your computer.

If you want to, you can specify the timezone. For my location, Poland (UTC +2) it would be:

from datetime import datetime, timedelta
now = datetime.utcnow() + timedelta(hours = 2)

print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)

or you can use a pytz package -> https://pypi.python.org/pypi/pytz


Thank you! Appreciate it!


You're very welcome :slight_smile:


Just cuious: Any idea where the CodeAcademy servers are located? From what I can tell, the time difference puts it somewhere is 6 hours ahead of where I am (Seattle, WA). Are they located in ... Iceland? :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.