Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python time altzone() Method

  • Last Updated : 05 Nov, 2021

Python altzone() method is used to return the offset of the local DST timezone, in seconds west of UTC. We can also get the current time between the current time zone and UTC by using the timezone and altzone method.

Syntax:

time.altzone

Example:

Python3




# import the time module
import time
  
# display altzone
print(time.altzone)

Output:

25200

Example: Python program to get the current time between current time zone and UTC by using timezone  and altzone method

Python3




# import time module
import time
  
# get_zone function to get the
# current time between current time zone and UTC
# by using timezone  and altzone method
def get_zone():
    dst = time.daylight and time.localtime().tm_isdst
      
    # get altzone if there exists dst otherwise
    # get timezone
    offset = time.altzone if dst else time.timezone
      
    # check if offset greater than 0
    westerly = offset > 0
  
    # get the minutes and seconds
    minutes, seconds = divmod(abs(offset), 60)
    hours, minutes = divmod(minutes, 60)
      
    # return the timezone
    return '{}{:02d}{:02d}'.format('-' if westerly else '+', hours, minutes)
  
# call the function
get_zone()

Output:

+0000

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!