PyDocs

Nav

Data Types

datetime.astimezone

  • datetime.astimezone(tz=None)
Convert to local time in new timezone tz.
Changed in 3.3, 3.6
  • 3.3: tz now can be omitted.
  • 3.6: The astimezone() method can now be called on naive instances that are presumed to represent system local time.
1 Example
>>> tz1 = KabulTz()

>>> # Datetime before the change
>>> dt1 = dt.datetime(1900, 11, 21, 16, 30, tzinfo=tz1)
>>> print(dt1.utcoffset())
4:00:00

>>> # Datetime after the change
>>> dt2 = dt.datetime(2006, 6, 14, 13, 0, tzinfo=tz1)
>>> print(dt2.utcoffset())
4:30:00

>>> # Convert datetime to another time zone
>>> dt3 = dt2.astimezone(dt.timezone.utc)
>>> dt3
datetime.datetime(2006, 6, 14, 8, 30, tzinfo=datetime.timezone.utc)
>>> dt2
datetime.datetime(2006, 6, 14, 13, 0, tzinfo=KabulTz())
>>> dt2 == dt3
True
from the Python docs
See Also
No see-alsos for datetime/datetime.astimezone
0 Notes
No notes for datetime.astimezone