开发者

How to set timezone in python using os.environ

开发者 https://www.devze.com 2023-03-02 05:27 出处:网络
example: 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 Time

example:

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 Time but

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.                         

Was there an easier way to get back to my correct time? Yes, just unset the TZ environment variable.

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

Note, even though TZ was adjusted for daylight saving time, will you get the correct time 5 months from now? When does daylight saving time go into effect? The TZ value shown below adjust for dst, only during the correct dates. For instance, this entry goes into effect April, the first week, at 2am, and ends October the 5th week, at 2am. Note 10.5.0 stands for the 5th week in October, and not the 5th day.

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


From the 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消