How to set timezone in python using os.environ
例:
1 | os.environ['TZ'] ="CST+06CDT,M4.1.0,M10.5.0" |
我可以理解CST,06(偏离UTC ??或GMT),CDT ==中央夏令时
但
M4.1.0和M10.5.0是什么意思?
这是我发现的:
出口TZ = EST05EDT
EST取自下表。 需要五个小时才能获得UTC,因此05.目前EDT,东部日光正在生效。
TZ=。
DST时区
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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环境变量即可。
1 2 3 | $ unset TZ $ date Sun Aug 22 10:17:35 EDT 2004 |
请注意,即使TZ针对夏令时进行了调整,您是否会在5个月后获得正确的时间? 夏令时什么时候生效? 下面显示的TZ值仅在正确日期期间调整为dst。 例如,此条目将于4月,第一周,凌晨2点生效,并于10月5日结束,凌晨2点结束。 注释10.5.0代表10月的第5周,而不是第5天。
1 | $ export TZ=EST+5EDT,M4.1.0/2,M10.5.0/2 |
从python手册:
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.