Python的time.time()时区是否具体? [英] Is Python's time.time() timezone specific?
问题描述
调用 time.time()
从不同的时区,同时产生不同的结果?这可能归结于 epoch
的定义,它在文档(以及我在互联网上不那么深入的搜索)上没有提及时区。 p>
另外,假设time.time()已经从具有不同时区的地方调用,并转换为UTC datetime
s他们的机器,他们都会给出相同的UTC时间?
是的, time.time()
返回自指定的纪元以来的秒数。请注意,在大多数系统上,这不是不包含闰秒,尽管它是可能配置您的系统时钟包括他们。在cpython上, time.time
被实现为根据§27.23.2.4调用C函数 time
。 C标准中的2不必使用指定的纪元:
time
函数确定当前的日历时间。值的编码是
未指定。
几乎每个操作系统(包括Linux,Mac OSX,Windows和所有其他Unixes),时代是 1970-1-1,00:00 UTC ,在这些系统上 time.time
是与时区无关的。
Apologies for asking too basic question but I couldn't get it cleared after reading docs. It just seems that I am missing or have misunderstood something too basic here.
Does calling time.time()
from different timezones, at the same time produce different results? This maybe comes down to definition of epoch
, which on the docs (and on my not-so-deep search on the Internet), has no mentions of the timezone.
Also, suppose time.time() has been called from places with different timezones, and converted to UTC datetime
s on their machines, will they all give same UTC time?
Yes, time.time()
returns the number of seconds since an unspecified epoch. Note that on most systems, this does not include leap seconds, although it is possible to configure your system clock to include them. On cpython, time.time
is implemented as a call to the C function time
, which per §27.23.2.4.2 of the C standard does not have to use a specified epoch:
The
time
function determines the current calendar time. The encoding of the value is unspecified.
On virtually every OS (including Linux, Mac OSX, Windows, and all other Unixes), the epoch is 1970-1-1, 00:00 UTC, and on these systems time.time
is timezone-independent.
这篇关于Python的time.time()时区是否具体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!