class tzinfo – Timezone information
An abstract base class for time zone information objects. These are used by the
datetime and time classes to provide
a customizable notion of time adjustment (for example, to account for time zone
and/or daylight saving time).
For many use cases, it is recommended to use the timezone
class, which models fixed offsets from UTC. If these are not suitable, a
subclass of tzinfo can be created, with all abstract methods
implemented.
- class datetime.tzinfo
- abstract dst(dt)
Return the daylight saving time (DST) adjustment as a
timedeltaobject, orNoneif DST information isn’t known, given a particulardt.
- abstract tzname(dt)
Return the time zone name as a string, or
Noneif the time zone name isn’t known, given a particulardt.
- abstract utcoffset(dt)
Return the UTC offset as a
timedeltaobject, orNoneif the UTC offset isn’t known, given a particulardt.
- fromutc(dt)
Convert a UTC time given by
dtto the local time in the time zone represented by this object. This method is called bydatetime.datetime.astimezone().Note that the datetime object passed to this method is in UTC, but the
datetime.tzinfoattribute is already set to the desired tzinfo. This function should merely subtract the desired UTC offset from the passed-in datetime object.The default implementation works well for coverting between timezones, but can handle the hours around some DST transitions incorrectly. This method can be overridden to handle this, as well as other exceptional situations. Please read PEP 495 for more information.
- isoformat(dt)
Return a string representing the time zone in ISO 8601 format, given a particular
dt.