Python time tzset() Method
Description
Python time tzset() reinitializes time-related settings based on the environment variable TZ.
Standard TZ environment variable format:
std offset [dst [offset [,start[/time], end[/time]]]]
Parameters
- std and dst:Three or more abbreviation letters for time. Passed to time.tzname.
- offset:Offset from UTC, format: [+|-]hh[:mm[:ss]] {h=0-23, m/s=0-59}.
- start[/time], end[/time]:Date when DST starts taking effect. The format is m.w.d — representing the month, week number, and day of the date. w=1 refers to the first week of the month, while w=5 refers to the last week of the month. 'start' and 'end' can be one of the following formats:
- Jn:Julian day n (1 <= n <= 365). Leap year days (February 29) are not counted.
- n:Julian day (0 <= n <= 365). Leap year days (February 29) are counted.
- Mm.n.d:The month, week number, and day of the date. w=1 refers to the first week of the month, while w=5 refers to the last week of the month.
- time:(Optional) The time when DST starts taking effect (24-hour clock). Default value is 02:00 (local time in the specified time zone).
Syntax
time.tzset()
Parameters
- NA。
Return Value
This function has no return value.
Example
The following example demonstrates how to use the tzset() function:
#!/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')
The above example produces the following output:
13:00:40 02/17/09 EST 05:00:40 02/18/09 AEDTOther Extensions