How to convert a list of timestamps in an excel file from UTC to San Francisco time (Pacific Time) with python? [duplicate]

扶醉桌前 提交于 2019-12-13 10:22:52

问题


Let's say I have an excel file named "hello123.xlsx". There is a column of timestamps that has a lot of rows (more than 50,000 rows). The image attached here is basically what the file looks like:

enter image description here

These timestamps are actually gathered from twitter streaming API. Now I need to convert them from GMT to San Francisco local time, which should be Pacific Time (PT) or specifically Pacific Daylight Time (PDT, UTC-7).

I searched some methods online but still failed to do so. I'm a beginner of python and I hope someone can help me figure it out. :)


回答1:


Please take a look at this post: need to convert UTC (aws ec2) to PST in python

from datetime import datetime
from pytz import timezone
import pytz

date_format='%m/%d/%Y %H:%M:%S %Z'
date = datetime.now(tz=pytz.utc)
print 'Current date & time is:', date.strftime(date_format)

date = date.astimezone(timezone('US/Pacific'))

print 'Local date & time is  :', date.strftime(date_format)


来源:https://stackoverflow.com/questions/49990152/how-to-convert-a-list-of-timestamps-in-an-excel-file-from-utc-to-san-francisco-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!