dst() method of timezone class in Python

The class timezone holds only essential attributes and behaviour required for a time zone: an offset from UTC and a name. Apart from this it does not support any other semantics like DST.

Timezone Updated 9 Aug 2021 1 min read

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

python
# 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

Output
An NYC morning:

07:00:00-04:00

Information on Daylight Saving Time:

None