How to convert a list of timestamps in an excel fi

2019-09-20 18:15发布

This question already has an answer here:

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条回答
forever°为你锁心
2楼-- · 2019-09-20 18:48

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)
查看更多
登录 后发表回答