如何使用python将excel文件中的时间戳列表从UTC转换为旧金山时间(太平洋时间)? [英] How to convert a list of timestamps in an excel file from UTC to San Francisco time (Pacific Time) with python?

查看:111
本文介绍了如何使用python将excel文件中的时间戳列表从UTC转换为旧金山时间(太平洋时间)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为hello123.xlsx"的 Excel 文件.有一列时间戳有很多行(超过 50,000 行).这里附上的图片基本上就是文件的样子:

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:

在此处输入图片描述

这些时间戳实际上是从 Twitter 流 API 收集的.现在我需要将它们从格林威治标准时间转换为旧金山当地时间,这应该是太平洋时间 (PT) 或特别是太平洋夏令时 (PDT,UTC-7).

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).

我在网上搜索了一些方法,但仍然没有这样做.我是python的初学者,我希望有人能帮我弄清楚.:)

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. :)

推荐答案

请看这篇文章:需要在python中将UTC(aws ec2)转换为PST

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)

这篇关于如何使用python将excel文件中的时间戳列表从UTC转换为旧金山时间(太平洋时间)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆