问题描述
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?
推荐答案
说:
我将其解释为
另请参见。这似乎证实了以下观念:实际上,历元始终假定为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日开始测量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!