Timestamp中的astimezone与tz_localize、astimezone的区别

import pytz
import pandas as pd

pd.Timestamp('2009-01-05T15',tz='utc')  
# Timestamp('2009-01-05 15:00:00+0000', tz='UTC')


#  已知当前utc时间,得到东八区的时间
pd.Timestamp('2009-01-05T15',tz='utc').astimezone(pytz.timezone("Asia/Shanghai"))
# Timestamp('2009-01-05 23:00:00+0800', tz='Asia/Shanghai')

#  已知当前utc时间,得到东八区的时间
pd.Timestamp('2009-01-05T15',tz='utc').tz_convert(pytz.timezone("Asia/Shanghai"))
# Timestamp('2009-01-05 23:00:00+0800', tz='Asia/Shanghai')


#  已知时间,确定当前时间是东八区的时间
# 等同于pd.Timestamp('2009-01-05T15',tz='Asia/Shanghai')
pd.Timestamp('2009-01-05T15'). (pytz.timezone("Asia/Shanghai"))
#  Timestamp('2009-01-05 15:00:00+0800', tz='Asia/Shanghai')

astimezone和tz_convert还有更细致的区别, 等在实践中深入了解吧

你可能感兴趣的:(python,pandas,pandas,python,开发语言)