datetime strftime does not output correct timestamp

六月ゝ 毕业季﹏ 提交于 2020-01-14 14:56:29

问题


The following:

>>> from dateutil.parser import parse
>>> parse("2013-07-02 00:00:00 -0000")
datetime.datetime(2013, 7, 2, 0, 0, tzinfo=tzutc())

shows that the time should be 12am on July 2nd 2013 in UTC.

However:

>>> parse("2013-07-02 00:00:00 -0000").strftime("%s")
'1372744800'

1372744800 is actually Tue, 02 Jul 2013 06:00:00 UTC, which is wrong. Very confused.


回答1:


See this question: Convert python datetime to epoch with 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.



来源:https://stackoverflow.com/questions/17433056/datetime-strftime-does-not-output-correct-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!