This article mainly introduces the use of the Tzset () method of operation time in Python, which is the basic knowledge in Python learning, and the friends who need it can refer to the following
The Tzset () method resets the time conversion rules for the library routines used. The environment variable TZ specifies how to complete this operation.
Standard format for TZ environment variables (spaces are added for clarity):
The code is as follows:
STD offset [DST [offset [, Start[/time], End[/time]]]
STD and DST: three-or-more alphanumeric time zone abbreviations. These will be propagated to Time.tzname.
Offset: Offset offset in the form of:. Hh[:mm[:ss]]. This indicates that the value added local time arrives in UTC. If preceded by a "-", the time zone is east of Meridian; otherwise, it is the west. If the following DST is not offset, the summer time is assumed to be the next standard time for one hour.
Start[/time], End[/time]: means when changing to and coming back from daylight. The start and end dates are formatted by doing one of the following:
Jn: In Julian date n (1 <= n <= 365). Leap Day is not counted, so the February 28 of each year is the 59th and March 1 is 60 days.
N: The null-starting Julian date (0<= n<=365). Leap year days are counted, and can mean February 29.
MM.N.D: X Day (0<= d<= 6) or week N of the year (1 <= n <=5,1<= m <=12, where 5 per week means "at the last D Sun M", which may occur in any of the four or fifth weeks). Week 1 is where D-day occurs in the first week. 0 is Sunday.
Time: This differs from the same format offset by the absence of a leading sign ("-" or "+") that is allowed. By default, if time is not given, it is 02:00:00.
Grammar
The following is the syntax for the Tzset () method:
?
Parameters
NA
return value
This method does not return any values.
Example
The following example shows the use of the Tzset () method.
?
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/python Import time import os os.environ[' TZ ' = ' est+05edt,m4.1.0,m10.5.0 ' Time.tzset () print time.strftime (' %x%x%Z ') os.environ[' TZ ' = ' aest-10aedt-11,m10.5.0,m3.5.0 ' Time.tzset () print time.strftime ('%x%x%Z ') |
When we run the above program, it produces the following results:
?
1 2 |
13:00:40 02/17/09 EST 05:00:40 02/18/09 AEDT |