TimezoneInfo

class astropy.time.TimezoneInfo(utc_offset=<Quantity 0. d>, dst=<Quantity 0. d>, tzname=None)[source]

Bases: datetime.tzinfo

Subclass of the tzinfo object, used in the to_datetime method to specify timezones.

It may be safer in most cases to use a timezone database package like pytz rather than defining your own timezones - this class is mainly a workaround for users without pytz.

Parameters
utc_offsetQuantity (optional)

Offset from UTC in days. Defaults to zero.

dstQuantity (optional)

Daylight Savings Time offset in days. Defaults to zero (no daylight savings).

tznamestring, None (optional)

Name of timezone

Examples

>>> from datetime import datetime
>>> from astropy.time import TimezoneInfo  # Specifies a timezone
>>> import astropy.units as u
>>> utc = TimezoneInfo()    # Defaults to UTC
>>> utc_plus_one_hour = TimezoneInfo(utc_offset=1*u.hour)  # UTC+1
>>> dt_aware = datetime(2000, 1, 1, 0, 0, 0, tzinfo=utc_plus_one_hour)
>>> print(dt_aware)
2000-01-01 00:00:00+01:00
>>> print(dt_aware.astimezone(utc))
1999-12-31 23:00:00+00:00

Methods Summary

dst(self, dt)

datetime -> DST offset in minutes east of UTC.

fromutc()

datetime in UTC -> datetime in local time.

tzname(self, dt)

datetime -> string name of time zone.

utcoffset(self, dt)

datetime -> timedelta showing offset from UTC, negative values indicating West of UTC

Methods Documentation

dst(self, dt)[source]

datetime -> DST offset in minutes east of UTC.

fromutc()

datetime in UTC -> datetime in local time.

tzname(self, dt)[source]

datetime -> string name of time zone.

utcoffset(self, dt)[source]

datetime -> timedelta showing offset from UTC, negative values indicating West of UTC