6

I am trying to convert the timestamp 1452454659 to its rfc3339 equivalent.

I am getting the output as:

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

When I pass this to influxdb it returns a time of:

2016-01-10T19:37:39Z

while I actually want the time in influxdb to be:

2016-01-11T01:07:39

I have even tried to pass only 2016-01-11T01:07:39, leaving out +5:30, but then it gives me no result.

What mistake am I making?

jkdev
  • 11,360
  • 15
  • 54
  • 77
Vishal Puliani
  • 201
  • 1
  • 3
  • 14
  • I do not want to use now() as my timestamp is already there as a string, and that is why i do not want to use "now()" – Vishal Puliani Jan 10 '16 at 18:29
  • the added part: *"I am getting the output as 2016-01-11T01:07:39+05:30, when i pass this to influxdb it returns a time of: 2016-01-10T19:37:39Z from influxdb while i actually want the time in influxdb to be 2016-01-11T01:07:39."* is unrelated to your question *"convert timestamp to rfc 3339"*. Ask a new question about your issues with influxdb specifically. – jfs Jan 11 '16 at 03:56
  • All timestamps in InfluxDB are UTC. There are no time zones nor time zone support. – beckettsean Jan 15 '16 at 00:51

3 Answers3

3

if your timestamp is from utc format, the following example may help you : (just replace the variable 'd' with your own timestamp)

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


--> 2016-01-10T09:33:33.865129Z

I based my answer on the following link : https://docs.python.org/2/library/datetime.html

Zohar81
  • 4,554
  • 5
  • 29
  • 82
3
>>> print datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-4]+"Z"
2016-01-10T10:27:45.89Z
Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
2

There is a specialized python package for this:

https://pypi.python.org/pypi/strict-rfc3339

Radek Hofman
  • 517
  • 3
  • 12