2024-06-01 03:07:05 发布
网友
这就是我所拥有的:
pat = '%Y-%m-%d %H:%M:%S +0000' my_time = time.strptime(task_time, pattern)
但是,如何将时区从:
my_time: 2016-06-15 23:27:52 +0000
到其他时区:
PDT
或者
-0700
结果是:
result = 2016-06-15 16:27:52 -0700
使用python包^{}可以使用以下简单脚本:
import arrow fmt = "YYYY-MM-DD HH:mm:ss Z" time = arrow.get("2016-06-15 23:27:52 +0000", fmt) time = time.to("US/Pacific") print(time.format(fmt))
2016-06-15 16:27:52 -0700
用pip install arrow安装箭头
pip install arrow
编辑:如果不想使用arrow包:
arrow
import time import calendar fmt = "%Y-%m-%d %H:%M:%S " t = calendar.timegm(time.strptime("2016-06-15 23:27:52 +0000", fmt + "+0000")) t -= 8 * 60 * 60 s = time.strftime(fmt + "-0700", time.gmtime(t)) print(s)
请注意,这是一个可怕的代码,如果您在生产中使用它,您肯定会被解雇,所以只需安装arrow包!你知道吗
使用python包^{} 可以使用以下简单脚本:
2016-06-15 16:27:52 -0700
用
pip install arrow
安装箭头编辑:如果不想使用
arrow
包:请注意,这是一个可怕的代码,如果您在生产中使用它,您肯定会被解雇,所以只需安装
arrow
包!你知道吗相关问题 更多 >
编程相关推荐