Saransh Mohapatra Saransh Mohapatra - 1 year ago 69
Python Question

Does Python's time.time() return the local or UTC timestamp?


in the Python time module return the system's time or the time in UTC?

Answer Source

The time.time() function returns the number of seconds since the epoch as seconds in UTC.

Here is some sample output I ran on my computer, converting it to a string as well.

Python 2.7.3 (default, Apr 24 2012, 00:00:54) 
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> ts = time.time()
>>> print ts
>>> import datetime
>>> st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
>>> print st
2012-12-15 01:21:05

The ts variable is the time returned in seconds. I then converted it to a string using the datetime library making it a string that is human readable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download