There is the Date.parse() in javascript which will give you a timestamp from a date string like yours but you can also put the string straight into the new Date()method as this will implicitly call the Date.parse()to give you a js date object. See
2 nodes I did to test my construction of a payload for InfluxDB - bit rough but for for an 'out' or 'batch' InfluxDB node and construct the times differently. Note Influx expects a time as microseconds.nanoseconds.
If you are using the influx batch node then that is what it expects. The timestamp in nanosecond, probably. However it is not entirely clear to me what the Time Precision setting in the advanced settings in the node does.
You can specify the precision for the timestamp so InfluxDB will interpret the integer correctly. If you set the advanced options as seconds, then there is no need to multiply the result of the parse.
Are you confident that is what it means, I know it would appear to mean that the timestamp should be provided in that format, but have you actually tried it and confirmed it works? When I looked into this subject a little while back it appeared to be more complex than one might think.
If you are correct then in the case here it would be simpler to leave the timestamp in milliseconds (so don't multiply by 10^6) and set it to ms in the node.
Reasonably confident although not tested. As the link to the InfluxDB docs shows an example of setting the precision in a CURL command, I see no reason why it would be different for the Node-RED node. They are all vaid InfluxDB time precisions.
Yes my mistake, set to ms and just use the Javascript parse. If, for instance, you used Tasmota in the epoch time format, you could set the InfluxDB node to seconds and just pass the timestamp straight through.
Thank you to all ... I dont know how to explain my situation. I am student at university and I received task in one subject.
The task consists of 2 parts:
1.) create "senzors" in JavaScript and send random values from senzors (simulate) senzors via MQTT procotol.
It is DONE and works fine.
I am sendit this JSON objects via JSON.stringify(senzor_values)
2.) the second part of my task is to receive the JSON objects in NODE-RED, than write from JSON values into Influx DB and the last make report from this data in grafana,
It is my task from university.
Now I am new in Node-RED
a) I added MQTT in node in the flow - I am receiving data - It IS OK
b) I added JSON node and set action to always convert JSON data to JSON object
c) then I send the output into debug and into influx DB and this is NOT OK - why?
Because when is see the measurement in INflux DB I see that DateTime values from JSON which I received
{
"deviceId": "e4c56af7-2efd-4e15-b35b-90b2161fb264",
"sensor": "temperature",
"value": 19,
"date": "2020-04-16T19:11:33.269Z"
}
on INflux DB was added data as a string not as a DateTime
SHOW FIELD KEYS
name: temperature
fieldKey fieldType
date string
deviceId string
sensor string
value float
It is the reason why I need to change or convert received DateTime string from JSON into DateTime format because I am importin directly this datas/values into INfluxDB.