在Python中将时间戳转换为RFC 3339

Vis*_*ani 6 python timestamp rfc3339

我正在尝试将时间戳转换1452454659为其等效的rfc3339。

我得到的输出为:

2016-01-11T01:07:39+05:30

当我将其传递给influxdb时,它将返回以下时间:

2016-01-10T19:37:39Z

而我实际上希望influxdb中的时间为:

2016-01-11T01:07:39

我什至只尝试通过2016-01-11T01:07:39,而没有通过+5:30,但是那没有结果。

我犯什么错误?

Zoh*_*r81 3

如果您的时间戳是 utc 格式,以下示例可能会帮助您:(只需将变量“d”替换为您自己的时间戳)

import datetime
d = datetime.datetime.utcnow()
print d.isoformat("T") + "Z"


--> 2016-01-10T09:33:33.865129Z
Run Code Online (Sandbox Code Playgroud)

我的答案基于以下链接:https ://docs.python.org/2/library/datetime.html