datetime.now()
and datetime.today()
return time in UTC on my computer even though the documentation says they should return local time.
Here's the script I ran:
#!/usr/bin/python
import time
import datetime
if __name__ == "__main__":
print(datetime.datetime.now())
print(datetime.datetime.today())
print(datetime.datetime.fromtimestamp(time.time()))
and here's the output:
2017-11-29 22:47:35.339914
2017-11-29 22:47:35.340399
2017-11-29 22:47:35.340399
The output of running date
right after it is:
Wed, Nov 29, 2017 3:47:43 PM
Why is my installation returning time in UTC?
What can I do get those functions to return local time?
PS We are in MST, which is UTC-7.
PS 2 I realize there are methods to convert a UTC time to local time, such as those explained in Convert a python UTC datetime to a local datetime using only python standard library?. However, I am trying to understand the cause of the fundamental problem and not looking for a method to patch the problem in my own code.
In response to comment by @jwodder:
The output of executing
print(time.altzone)
print(time.timezone)
print(time.tzname)
is:
-3600
0
('Ame', 'ric')