python在the秒返回什么 [英] What does python return on the leap second

查看:54
本文介绍了python在the秒返回什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python time datetime 模块在the秒返回什么?

What does python time and datetime module return on the leap second?

如果我打电话给我们,我们在 23:59:60.5 会得到什么?

What will I get when we are at 23:59:60.5 if I call:

  • time.time()
  • datetime.datetime.utcnow()
  • datetime.datetime.now(pytz.utc)

还有py2.7和py3之间有什么区别吗?

Also, any difference between py2.7 and py3?

为什么令人困惑(至少对我来说如此):

Why it is confusing (at least for me):

datetime文档中,我看到:

与时间模块不同,日期时间模块不支持leap秒.

Unlike the time module, the datetime module does not support leap seconds.

时间文档上,我看到有支持",用 strptime 解析时可leap秒.但是没有关于 time.time()的评论.

On the time docs I see there is "support" for leap seconds when parsing with strptime. But there is no comment about time.time().

我看到使用 time 可以得到:

>>> time.mktime(time.strptime('2016-06-30T23:59:59', "%Y-%m-%dT%H:%M:%S"))
1467327599.0
>>> time.mktime(time.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S"))
1467327600.0
>>> time.mktime(time.strptime('2016-07-01T00:00:00', "%Y-%m-%dT%H:%M:%S"))
1467327600.0

然后 datetime 爆炸了:

>>> dt.datetime.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S")
Traceback (most recent call last):
  File "<stdin>", line 1, in &lt;module>
ValueError: second must be in 0..59

那我在那个确切的时间(the秒中间)会得到什么?

Then what will I get at that exact time (in the middle of the leap second)?

我已经读到了橡胶时间,时钟变慢,重复秒数以及各种疯狂的想法,但是我对python有什么期望?

I have read about rubber times, clocks slowing down, repeating seconds, and all kind of crazy ideas, but what should I expect on python?

注意:如果您想知道我是否还有更好的方法来解决这个问题,,秒将至!!!

Note: In case you wonder if I don't have anything better to do that care about it, a leap second is approaching!!!!

推荐答案

偶尔会手动安排Le秒.当前,计算机时钟无法满足leap秒的要求.没有标准告诉他们预先插入一个.相反,计算机时钟会通过NTP协议定期重新同步其时间,并在插入time秒后自动进行调整.

Leap seconds are occasionally manually scheduled. Currently, computer clocks have no facility to honour leap seconds; there is no standard to tell them up-front to insert one. Instead, computer clocks periodically re-synch their time keeping via the NTP protocol and adjust automatically after the leap second has been inserted.

接下来,计算机时钟通常将时间报告为自纪元以来的.在转换秒数以包括leap秒时,要由 datetime 模块来调整其记帐.目前尚不这样做. time.time()将仅基于秒开始报告时间计数.

Next, computer clocks usually report the time as seconds since the epoch. It'd be up to the datetime module to adjust its accounting when converting that second count to include leap seconds. It doesn't do this at present. time.time() will just report a time count based on the seconds-since-the-epoch.

因此,the秒正式生效后,没有什么不同,除了您的计算机时钟只有一秒钟的时间.

So, nothing different will happen when the leap second is officially in effect, other than that your computer clock will be 1 second of for a little while.

datetime 的问题仅涵盖代表的leap秒时间戳,而不能.无论如何都不会要求这样做.

The issues with datetime only cover representing a leap second timestamp, which it can't. It won't be asked to do so anyway.

这篇关于python在the秒返回什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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