Timestamp to UTC time

Hello everyone,

I have a script that makes a CSV file from my data.
The time is an string of numbers (10) and i would like to see it like the UTC time (15).
I tried the command .format ("YYYY-MM-DD HH:mm:ss) but it doesnt work.

can someone help me please ?

Thanks in advance.


[{"id":"e772383a60295230","type":"function","z":"5984625998a10b6e","name":"Set data","func":"\nmsg.payload = {\n    \"Tijd\" : (msg.payload.utcTimeStamp),\n    \"Totaal_vermogen\" : msg.payload.totalPower,\n    \"Totaal_import\": msg.payload.totalImportEnergy,\n    \"Totaal_export\": msg.payload.totalExportEnergy,\n    \"Frequentie\": (msg.payload.measuredFrequency/1000000).toFixed(2),\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":1140,"wires":[["cb2f7d9066defbde"]]}]

Try wrapping the timestamp in a new Date. While that produces a JavaScript Date object, when you convert to CSV, that should automatically translate to ISO8601 date format which is always in UTC.

"Tjd": (new Date(msg.payload.utcTimeStamp)),

If that doesn't work, Date objects have a toISO function. You can look it up on MDN.

1 Like

Thanks !

Now he takes the UTC values but is there a possibility that i can use the utc+2

You did say that you wanted UTC. :slight_smile:

Generally best to keep data in UTC to be honest if you can. It avoids many nasty DST/Timezone issues.

But there are plenty of other things you can do with dates. You could also check out Node.js's international libraries for help with converting to other zones and standard formats.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.