pandas.Timestamp.astimezone#

Timestamp.astimezone(tz)#

Convert timezone-aware Timestamp to another time zone.

This method is used to convert a timezone-aware Timestamp object to a different time zone. The original UTC time remains the same; only the time zone information is changed. If the Timestamp is timezone-naive, a TypeError is raised.

Parameters:
tzstr, pytz.timezone, dateutil.tz.tzfile or None

Time zone for time which Timestamp will be converted to. None will remove timezone holding UTC time.

Returns:
convertedTimestamp
Raises:
TypeError

If Timestamp is tz-naive.

See also

Timestamp.tz_localize

Localize the Timestamp to a timezone.

DatetimeIndex.tz_convert

Convert a DatetimeIndex to another time zone.

DatetimeIndex.tz_localize

Localize a DatetimeIndex to a specific time zone.

datetime.datetime.astimezone

Convert a datetime object to another time zone.

Examples

Create a timestamp object with UTC timezone:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651', tz='UTC')
>>> ts
Timestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')

Change to Tokyo timezone:

>>> ts.tz_convert(tz='Asia/Tokyo')
Timestamp('2020-03-15 00:32:52.192548651+0900', tz='Asia/Tokyo')

Can also use astimezone:

>>> ts.astimezone(tz='Asia/Tokyo')
Timestamp('2020-03-15 00:32:52.192548651+0900', tz='Asia/Tokyo')

Analogous for pd.NaT:

>>> pd.NaT.tz_convert(tz='Asia/Tokyo')
NaT