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

后端 未结 5 2004
我寻月下人不归
我寻月下人不归 2020-12-20 14:12

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

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 14:33

    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.

提交回复
热议问题