Python Pandas - Convert Timestamp to another time zone

PythonPandasServer Side ProgrammingProgramming

Convert Timestamp to another time zone, use the timestamp.tz_convert(). Set the time zone as the parameter. At first, import the required libraries −

import pandas as pd

Create the timestamp object in Pandas. We have also set the timezone

timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')

Convert timezone of timestamp

timestamp.tz_convert('Australia/Brisbane'))

Example

Following is the code

import pandas as pd

# set the timestamp object in Pandas
# we have also set the timezone
timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')

# display the Timestamp
print("Timestamp...\n", timestamp)

# convert timezone
print("\nConvert the Timestamp timezone...\n",
timestamp.tz_convert('Australia/Brisbane'))

Output

This will produce the following code

Timestamp...
 2021-10-14 15:12:34.261811624-04:00

Convert the Timestamp timezone...
 2021-10-15 05:12:34.261811624+10:00
raja
Updated on 13-Oct-2021 07:14:50

Advertisements