Python time.tzset() Function Last Updated : 05 Aug, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In Python, the tzset() function of the time module is based on the re-initialization settings using the environment variable TZ. tzset() method of time module in python resets the time transformation protocol. this timezone means non-DST seconds west of UTC time and altzone means DST seconds west of UTC time. The TZ environment variable's conventional form is: std offset [dst [offset [,start[/time], end[/time]]]] Where the components are: std and dst: It is time zone contractions that are given by three or more alphanumeric values. These will be scattered into tzname() function of time in python.offset: In tzset(), the offset is of the form: ± hh[:mm[:ss]]. This indicates the value-added of the local time to arrive at UTC. The timezone is east of the Prime Meridian if preceded by a ‘-‘ sign. Else, it is west. Summertime is assumed to be one hour before the standard time if no offset follows DST.start[/time], end[/time]: Shows when to switch to and back from DST. The start and end dates follow one of the following formats:Jn: The Julian day n where n is in the range from 1 to 365 (1 <= n <= 365). In this, we do not count leap days, so in all years February 28 is day 59 and March 1 is day 60.n: The zero-based Julian day (0 <= n <= 365) which is in the range of 0 to 365. In this, we count leap days, and it is possible to point to February 29.Mm.n.d: The d’th day (0 <= d <= 6) of week n of month m of the year (1 <= n <= 5, 1 <= m <= 12, where week 5 means “the last d day in month m” which may occur in either the fourth or the fifth week). Week 1 is the first week in which the d’th day occurs. Day zero is a Sunday.time: This follows the same format as offset except that the leading sign (‘-‘ or ‘+’) is not allowed in this. This takes default time as 02:00:00 if it is not given. Syntax: time.tzset() Parameters: NA Return Value: Does not return any value. Note: Although in many cases, if we change the TZ environment variable it may affect the output of functions like localtime() without calling tzset(), this behavior should not be relied on. The TZ environment variable should contain no whitespace. Example 1: Python3 # time.tzset() Function in python # importing time and os module import time import os # Define TZ environment variable os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) # Define TZ environment variable again os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) Output08:47:24 11/19/21 EST 00:47:24 11/20/21 AEDT Example 2: Python3 # time.tzset() Function in python # importing time and os module import time import os # Define TZ environment variable os.environ['TZ'] = 'UTC' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) # Define TZ environment variable again os.environ['TZ'] = 'Europe/Amsterdam' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) Output12:14:00 11/23/21 UTC 13:14:00 11/23/21 CET Example 3: Python3 # time.tzset() Function in python # importing time and os module import time import os # Define TZ environment variable os.environ['TZ'] = 'Australia/Melbourne' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) # Define TZ environment variable again os.environ['TZ'] = 'Egypt' # reset the time conversion rules time.tzset() # print time print(time.strftime('%X %x %Z')) Output23:14:00 11/23/21 AEDT 14:14:00 11/23/21 EET Comment More infoAdvertise with us Next Article Python time.tzset() Function R rushi_javiya Follow Improve Article Tags : Python Python time-module Practice Tags : python Similar Reads Python | time.monotonic() method Python time.monotonic() method is used to get the value of a monotonic clock. A monotonic clock is a clock that can not go backward. As the reference point of the returned value of the monotonic clock is undefined, only the difference between the results of consecutive calls is valid. Python time.mo 2 min read Python | time.monotonic_ns() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.monotonic_ns() method of time module in Python is used to get the value of a monotonic clock in nanoseconds. This method is similar to time.monotonic() method which returns 3 min read time.perf_counter() function in Python The time module provides various time-related functions. We must import the time module before using perf_counter() so we can access the function without throwing any errors.The perf_counter() function always returns the float value of time in seconds. Return the value (in fractional seconds) of a p 4 min read Python time.perf_counter_ns() Function Python time.perf_counter_ns() function gives the integer value of time in nanoseconds. Syntax: from time import perf_counter_ns We can find the elapsed time by using start and stop functions. We can also find the elapsed time during the whole program by subtracting stoptime and starttime Example 1: 1 min read time.process_time() function in Python time.process_time() is a function in Pythonâs time module that returns the CPU time used by the current process as a floating-point number in seconds. Unlike time.time(), which measures real (wall-clock) time, time.process_time() focuses on the time spent by the CPU executing the process, excluding 4 min read Python | time.process_time_ns() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.process_time_ns() method of time module in Python is used to get the sum of the system and user CPU time of the current process in nanoseconds. This method does not include 5 min read time.sleep() in Python Python time sleep() function suspends execution for the given number of seconds. Syntax of time sleep() Syntax : sleep(sec) Parameters : sec : Number of seconds for which the code is required to be stopped. Returns : VOID. Sometimes, there is a need to halt the flow of the program so that several 4 min read time.strftime() function in Python time.strftime(format[, t]) function in Python's time module converts a given time tuple (t) or struct_time object into a formatted string based on the specified format. If t is not provided, the function uses the current local time. The format must be a string and a ValueError is raised if any field 5 min read Python time strptime() function The strptime() function in Python is used to format and return a string representation of date and time. It takes in the date, time, or both as an input, and parses it according to the directives given to it. It raises ValueError if the string cannot be formatted according to the provided directives 2 min read Python | time.time() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.time() method of Time module is used to get the time in seconds since epoch. The handling of leap seconds is platform dependent. Note: The epoch is the point where the time 2 min read Like