datetime strftime不输出正确的时间戳 [英] datetime strftime does not output correct timestamp
问题描述
以下内容:
>>> from dateutil.parser import parse
>>> parse("2013-07-02 00:00:00 -0000")
datetime.datetime(2013, 7, 2, 0, 0, tzinfo=tzutc())
显示时间应该是2013年7月2日的12点,UTC。
shows that the time should be 12am on July 2nd 2013 in UTC.
:
>>> parse("2013-07-02 00:00:00 -0000").strftime("%s")
'1372744800'
1372744800其实是星期二,2013年7月02日06:00:00 UTC,这是错误的。非常困惑。
1372744800 is actually Tue, 02 Jul 2013 06:00:00 UTC, which is wrong. Very confused.
推荐答案
看到这个问题:使用strftime将python datetime转换为epoch
t实际上支持%s作为strftime的参数(如果
检查
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
它不在列表中),唯一的原因是工作是因为Python
将信息传递到系统的strftime,它使用您的
本地时区。
Python doesn't actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it's not in the list), the only reason it's working is because Python is passing the information to your system's strftime, which uses your local timezone.
这篇关于datetime strftime不输出正确的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!