简体   繁体   English

Python datetime strptime解析错误,为什么在'2008-10-26 01:00:00'和'2008-10-26 00:00:00'之间需要两个小时?

[英]Python datetime strptime parsing error, why is two hours between '2008-10-26 01:00:00' and '2008-10-26 00:00:00'?

I'm manipulating timedates and I've found something strange: I've just created a simple function to transform dates into datetimes (in seconds) and I've found this: 我正在操纵日期,并且发现了一些奇怪的东西:我刚刚创建了一个简单的函数,可以将日期转换为日期时间(以秒为单位),我发现了这一点:

>>> import time
>>> from datetime import datetime
>>> parsefunc = lambda date : time.mktime(datetime.strptime(date, '%Y-%m-%d %H:%M:%S').timetuple())
>>> parsefunc('2008-10-25 01:00:00')-parsefunc('2008-10-25 00:00:00')
3600.0

All ok, there is 3600 s in one hour. 好的,一小时内有3600秒。

>>> parsefunc('2008-10-26 01:00:00')-parsefunc('2008-10-26 00:00:00')
7200.0

But here there is 7200 s of difference. 但是这里相差7200 s。

Does anyone know what is happening? 有人知道发生了什么吗? Is any library deprecated? 是否已弃用任何库? I've found some other dates when there is the same problem: '2009-10-25 00:00:00', '2010-10-31 00:00:00', '2011-10-30 00:00:00', '2012-10-28 00:00:00', '2013-10-27 00:00:00', '2014-10-26 00:00:00', '2015-10-25 00:00:00', '2016-10-30 00:00:00', '2017-10-29 00:00:00' and '2018-10-28 00:00:00' 遇到相同问题时,我还发现了其他一些日期:“ 2009-10-25 00:00:00”,“ 2010-10-31 00:00:00”,“ 2011-10-30 00:00: 00”,“ 2012-10-28 00:00:00”,“ 2013-10-27 00:00:00”,“ 2014-10-26 00:00:00”,“ 2015-10-25 00: 00:00','2016-10-30 00:00:00','2017-10-29 00:00:00'和'2018-10-28 00:00:00'

Thanks in advance, I can avoid this problem but I'm curious why is this happening. 预先感谢,我可以避免这个问题,但我很好奇为什么会这样。

好的,我刚刚发现了为什么会这样,这只是时间的变化:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM