Dst() method of timezone class in Python

Overview:

  • In several parts of the world Daylight Saving Time is observed during summer. When winter comes it is reversed. The timezone class does not support any scheme like DST which makes the UTC offset different for different periods of the year. Hence this method always returns None.

Example:

# An example Python program printing the available DST information from a # timezone instance

# import the classes
from datetime import timedelta, timezone, time

# Create time 
threeHrsbehind = timedelta(hours = -4)
edt = timezone(threeHrsbehind, "Eastern Daylight Time")
nycMorning = time(hour=7, tzinfo = edt)

# Print the time
print("An NYC morning:")
print(nycMorning)

# Will return None as long as DST is not supported
print("Information on Daylight Saving Time:")
print(nycMorning.dst())

Output:

An NYC morning:

07:00:00-04:00

Information on Daylight Saving Time:

None

 


Copyright 2024 © pythontic.com