在Python中,由time()返回的纪元时间是否始终从1970年1月1日开始测量? [英] In Python, is epoch time returned by time() always measured from Jan 1, 1970?

查看:340
本文介绍了在Python中,由time()返回的纪元时间是否始终从1970年1月1日开始测量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python中的纪元开始时间是否独立于平台(即始终为1970年1月1日)?

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

还是依赖于平台?

我想在运行Python的各种计算机上序列化日期时间(具有第二个精度),并能够在不同的平台上读回它们,可能还使用不同的编程语言(而不是Python)。

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?

推荐答案

文档说:


要了解时代,看看 gmtime(0)

我将其解释为

另请参见此Python-Dev线程。这似乎证实了以下观念:实际上,历元始终假定为1970/01/01,但这不是该语言明确保证的。

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.

这样做的结果是,至少对于Python,除非使用陌生且晦涩的平台,否则使用纪元时间可能还可以。对于使用非Python工具进行阅读,您可能还可以,但是要特别确保您需要阅读这些工具提供的文档。

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.

这篇关于在Python中,由time()返回的纪元时间是否始终从1970年1月1日开始测量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆