gpt4 book ai didi

Python:带有 pytz 时区标志的奇怪行为

转载 作者:太空宇宙 更新时间:2023-11-04 07:44:16 24 4
gpt4 key购买 nike

我在阿根廷,我的时间是 GMT-3 (http://wwp.greenwichmeantime.com/time-zone/south-america/argentina/)

我在玩 Pytz 时发现了一些奇怪的东西,看看:

from pytz import timezone
bsas = timezone('America/Argentina/Buenos_Aires')

gmt_plus_3 = timezone('Etc/GMT+3')
gmt_min_3 = timezone('Etc/GMT-3')

# Date and time at this momement: 2012-07-26 10:23:01

fmt = '%Y-%m-%dT%H:%M:%S'
datetime.now(bs).strftime(fmt) #'2012-07-26T10:23:01' <-- GOOD!

datetime.now(gmt_min_3).strftime(fmt) #'2012-07-26T16:25:21' <-- WRONG!

datetime.now(gmt_plus_3).strftime(fmt) #'2012-07-26T10:23:01' <-- GOOD! WTF!

我希望:

GMT-3 should be 10:23:01 and gives me 16:23:01
GMT+3 should be 16:23:01 and gives me 10:23:01

这是一个错误吗?我做错了吗??

最佳答案

这不是一个错误,它是一个功能(Wikipedia: Tz_database):

Etc 的特殊区域用于某些行政区域,特别是表示协调世界时的“Etc/UTC”。为了符合 POSIX 风格,那些以“Etc/GMT”开头的区域名称的符号与大多数人期望的相反。在这种风格中,GMT 以西的区域名称中有一个正号,而东部的区域名称中有一个负号(例如,“Etc/GMT-14”比 GMT 早/东 14 小时。)

关于Python:带有 pytz 时区标志的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670425/

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