How to Use the tzset () method for time operations in Python, pythontzset
The tzset () method resets the time conversion rules of the Library Routines used. The environment variable TZ specifies how to complete this operation.
Standard Format of TZ environment variables (spaces are added for clarity ):
Copy codeThe 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