In Python, is epoch time returned by time() always measured from Jan 1, 1970?

Epoch time (unix time) is a standard term:

http://en.wikipedia.org/wiki/Unix_time

Unix time, or POSIX time, is a system for describing instances in time, defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), 1 January 1970,[note 1] not counting leap seconds.[note 2] It is used widely in Unix-like and many other operating systems and file formats. It is neither a linear representation of time nor a true representation of UTC.[note 3] Unix time may be checked on some Unix systems by typing date +%s on the command line

That means if you use the epoch times through Python, it will be consistent across platforms. Your best bet for consistency is to use UTC in all cases.


time() would always return the time from epoch, look at the documentation.

Please note that Epoch is always the number of seconds since 1970, but since the clock on different machines are not the same - you'll might experience some problems.

Citation:

The epoch is the point where the time starts. On January 1st of that year, at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970. To find out what the epoch is, look at gmtime(0).

And:

time.time()¶

Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.

(Both from Python documentation).


The documentation says:

To find out what the epoch is, look at gmtime(0).

I would interpret this to mean that no particular epoch is guaranteed.

See also this Python-Dev thread. That seems to confirm the notion that, in practice, the epoch is always assumed to be 1970/01/01, but that this is not explicitly guaranteed by the language.

The upshot of this is that, at least for Python, you're probably okay using epoch time unless you're dealing with strange and obscure platforms. For reading with non-Python tools, you're probably also okay, but to be extra sure you'd need to read the documentation those tools provide.

Tags:

Python

Time

Epoch