Can anyone help me covert the time into a format that influx db accepts. The aim is to pass time (including milliseconds) to influxdb.
Thanks
Can anyone help me covert the time into a format that influx db accepts. The aim is to pass time (including milliseconds) to influxdb.
Thanks
You probably need epoch time for influxDB
Try:
import datetime
import time
t = "2009-11-10T23:00:00Z"
print( time.mktime(datetime.datetime.strptime(t, "%Y-%m-%dT%H:%M:%SZ").timetuple()) )
Output:
1257874200.0
In Python you can convert the string representation to a datetime
object, convert that to a struct_time
, then convert that to an integer representing the UNIX epoch time.
from datetime import datetime
from time import mktime
time_str = "2009-11-10T23:00:00Z"
time_fmt = "%Y-%m-%dT%H:%M:%SZ"
dt = datetime.strptime(time_str, time_fmt)
time_tuple = dt.timetuple()
epoch = mktime(time_tuple)
print(epoch)
Output:
1257912000.0