Date and Time Functions pull different time


#1

https://www.codecademy.com/courses/python-beginner-en-zFPOx/0/5?curriculum_id=4f89dab3d788890003000096

I actually don't have a code problem, but it has come to my attention that the time is different from mine. I use US Central time, and the time seems to be 5 hours ahead.

I expect the date and time functions to provide my time, not some other time zone's. Please fix.

from datetime import datetime
now = datetime.now()

print '%s:%s:%s' % (now.hour, now.minute, now.second)


I get 4:08 when it is 11:08 at my house.


#2

It looks to be reading UTC time, while your time looks to be +7 hours east of the Prime Meridian (Greenwich), or -5 hours west of it.

What do you get with,

datetime.today()

?

Just this instant, I'm getting,

=> datetime.datetime(2017, 7, 22, 12, 2, 16, 584000)

which is my local time.

DOCS

https://docs.python.org/2/library/datetime.html


#3

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