This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

How to generate Timestamp to RFC3339 format ?
#1
Hi,

the command line:
local t2=os.time({year=2020, month=3, day=25, hour=9, min=51, sec=36, isdst = false})
t2 -> 1585126296
generate a short timestamp

how can I get a RFC3339 format long timestamp like ?
1465839830100400200
for
2016-06-13T17:43:50.1004002Z

this is required to insert data into InfluxDB with a specific timestamp
see https://docs.influxdata.com/influxdb/v1...._tutorial/

best regards
Reply
#2
Here's an example. Timestamp must be a string because 1465839830100400200 cannot be represented as a floating point number without precision loss.
Code:
ts = '1465839830100400200'
tsec = tonumber(ts:sub(1, -10))
tfrac = ts:sub(-9)
date = os.date('!%Y-%m-%dT%H:%M:%S.', tsec) .. tfrac .. 'Z'
log(date)
Reply
#3
thank you for your response
Reply


Forum Jump: