Tampa Tampa - 15 days ago 6
Python Question

python 2.7 how to use a time stamp that is utc on another server

This is my timestamp on my utc server:

2016-11-21T15:35
1479742500


Now for debugging purposes...

I convert to a datetime object but this is what I get:

datetime.datetime.fromtimestamp(1479742500)
2016-11-21 23:35:00+00:00


How do I fix so its 2016-11-21T15:35?

Answer

Use the proper method, utcfromtimestamp.

>>> import datetime
>>> datetime.datetime.fromtimestamp(1479742500)
datetime.datetime(2016, 11, 21, 7, 35)
>>> datetime.datetime.utcfromtimestamp(1479742500)
datetime.datetime(2016, 11, 21, 15, 35)