gpt4 book ai didi

python - datetime strftime 不输出正确的时间戳

转载 作者:行者123 更新时间:2023-11-28 16:42:34 24 4
gpt4 key购买 nike

以下内容:

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

显示 UTC 时间应该是 2013 年 7 月 2 日凌晨 12 点。

但是:

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

1372744800 实际上是 UTC 时间 2013 年 7 月 2 日 06:00:00,这是错误的。很困惑。

最佳答案

看到这个问题: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.

关于python - datetime strftime 不输出正确的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17433056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com