What does method time.tzset() do in Python?

PythonServer Side ProgrammingProgramming

The time.tzset() method resets the time conversion rules used by the library routines. It uses the environment variable TZ to determine how to do this. It also sets the variables tzname (from the TZ environment variable), timezone (non-DST seconds West of UTC), altzone (DST seconds west of UTC) and daylight (to 0 if this timezone does not have any daylight saving time rules, or to nonzero if there is a time, past, present or future when daylight saving time applies).

This function is only available on Unix. The standard format of the TZ environment variable is −

std offset [dst [offset [,start[/time], end[/time]]]]


You can use it as follows −

import time
import os
os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
print time.strftime('%X %x %Z')
os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
print time.strftime('%X %x %Z')


This will give the output −

13:00:40 02/17/09 EST
05:00:40 02/18/09 AEDT
Published on 08-Jan-2018 08:08:28