Logic Machine Forum
How to generate Timestamp to RFC3339 format ? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: How to generate Timestamp to RFC3339 format ? (/showthread.php?tid=2540)



How to generate Timestamp to RFC3339 format ? - olivier - 25.03.2020

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.7/write_protocols/line_protocol_tutorial/

best regards


RE: How to generate Timestamp to RFC3339 format ? - admin - 25.03.2020

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)



RE: How to generate Timestamp to RFC3339 format ? - olivier - 26.03.2020

thank you for your response