问题
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