This article mainly introduces how to use the tzset () method in Python, which is a basic knowledge in Python learning. For more information, see tzset () method to reset the time conversion rules of the library routine used. The environment variable TZ specifies how to complete this operation.
Standard format of TZ environment variables (spaces are added for clarity ):
The code is as follows:
Std offset [dst [offset [, start [/time], end [/time]
- Std and dst: The time zone abbreviation given by three or more letters and numbers. These will be propagated to time. tzname.
- Offset: the offset format is. hh [: mm [: ss]. This indicates that the value-added local time is in UTC. If "-" is added before, the time zone is east of the primary meridian; otherwise, it is West. If there is no offset from the following dst, the summer time is assumed to be the standard time of one hour in the future.
- Start [/time], end [/time]: indicates that when it changes to and from the summer order. The format of the start and end dates is to perform one of the following operations:
- Jn: on the Julian date N (1 <= n <= 365 ). Leap days are not counted. Therefore, the period from January 1, February 28 is 59th days and the period from January 1, March 1 is 60 days.
- N: The Julian date starting from scratch (0 <= N <= 365 ). The number of days in a leap year is counted and can be expressed as January 1, February 29.
- Mm. n. d: mm (1 <= n <= 5, 1 <= m <= 12, 5 indicates "m on the last day", which may occur in any of the Forth or fifth weeks ). Week 1 is where day d occurs in the first week. 0 is Sunday.
- Time: The difference between this offset with the same format is that no leading symbol ("-" or "+") is allowed. By default, if the time is not given, it is 02:00:00.
Syntax
The following is the syntax of the tzset () method:
time.tzset()
Parameters
Return value
This method does not return any value.
Example
The following example shows how to use the tzset () method.
#!/usr/bin/pythonimport timeimport osos.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 will produce the following results:
13:00:40 02/17/09 EST05:00:40 02/18/09 AEDT