TimezoneInfo#
- class astropy.time.TimezoneInfo(utc_offset=<Quantity 0. d>, dst=<Quantity 0. d>, tzname=None)[source]#
Bases:
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:
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
(dt)datetime -> DST offset as timedelta positive east of UTC.
datetime in UTC -> datetime in local time.
tzname
(dt)datetime -> string name of time zone.
utcoffset
(dt)datetime -> timedelta showing offset from UTC, negative values indicating West of UTC
Methods Documentation
- fromutc()#
datetime in UTC -> datetime in local time.