gpt4 book ai didi

python - 如何使用 os.environ 在 python 中设置时区

转载 作者:行者123 更新时间:2023-12-05 05:28:55 29 4
gpt4 key购买 nike

例子:

os.environ['TZ'] = "CST+06CDT,M4.1.0,M10.5.0"

I can understand CST, 06 (offset from UTC ?? or GMT) , CDT == Central Daylight Saving Timebut

What do M4.1.0 and M10.5.0 mean ?

Here is what i found:

export TZ=EST05EDT

EST was taken from the chart below. Five hours has to be added to get UTC, hence the 05. And currently EDT, Eastern Daylight, is in effect.

TZ=.

DST timezones

  0      BST for British Summer.                                
+400 ADT for Atlantic Daylight.
+500 EDT for Eastern Daylight.
+600 CDT for Central Daylight.
+700 MDT for Mountain Daylight.
+800 PDT for Pacific Daylight.
+900 YDT for Yukon Daylight.
+1000 HDT for Hawaii Daylight.
-100 MEST for Middle European Summer,
MESZ for Middle European Summer,
SST for Swedish Summer and FST for French Summer.
-700 WADT for West Australian Daylight.
-1000 EADT for Eastern Australian Daylight.
-1200 NZDT for New Zealand Daylight.

有没有更简单的方法来回到我正确的时间?是的,只需取消设置 TZ 环境变量。

  $ unset TZ
$ date
Sun Aug 22 10:17:35 EDT 2004

请注意,即使 TZ 已针对夏令时进行了调整,您会在 5 个月后得到正确的时间吗?夏令时何时生效?下面显示的 TZ 值仅在正确的日期期间针对夏令时进行调整。例如,此条目从 4 月第一周凌晨 2 点开始生效,到 10 月第 5 周凌晨 2 点结束。注意 10.5.0 代表十月的第 5 周,而不是第 5 天。

  $ export TZ=EST+5EDT,M4.1.0/2,M10.5.0/2

最佳答案

来自python manual :

The standard format of the TZ environment variable is (whitespace added for clarity):

std offset [dst [offset [,start[/time], end[/time]]]]

Mm.n.d The d‘th day (0 <= d <= 6) or week n of month m of the year (1 <= n <= 5, 1 <= m <= 12, where week 5 means “the last d day in month m” which may occur in either the fourth or the fifth week). Week 1 is the first week in which the d‘th day occurs. Day zero is Sunday.

关于python - 如何使用 os.environ 在 python 中设置时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5873857/

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