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

kaalus picture kaalus · Jan 6, 2013 · Viewed 7.4k times · Source

Is the epoch start time in Python independent of the platform (i.e. always 1/1/1970)?

Or is it platform dependent?

I want to serialize datetimes (with second accuracy) on various machines running Python, and be able to read them back on different platforms, possibly also using different programming languages (than Python). Is serializing epoch time a good idea?

Answer

BrenBarn picture BrenBarn · Jan 6, 2013

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.