The time difference of pandas.Timestamp is 8 hours, how to solve the problem of time zone?

 ~\Desktop 
 ip
Python 3.6.7rc2 (v3.6.7rc2:4893861ab5, Oct 13 2018, 17:34:23) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type "?" for help.

In [1]: import pandas as pd

In [2]: ts = pd.Timestamp(2017,6,19)

In [3]: ts
Out[3]: Timestamp("2017-06-19 00:00:00")

In [4]: tss = ts.timestamp()

In [5]: tss
Out[5]: 1497830400.0

In [6]: from datetime import datetime

In [7]: datetime.fromtimestamp(tss)
Out[7]: datetime.datetime(2017, 6, 19, 8, 0)

In [8]:

that"s it, very simple code. The solution now is to subtract 8 hours after finding timestamp. Is there any other solution?

Apr.21,2022

provides tz_localize and tz_convert functions in Pandas, where the former is used to convert timestamps to local time, while the latter can be used for conversion in any time zone.

Menu