Epoch time conversion to GMT +8

Hi

I got this code from this forum Converting epoch time. How do I convert it to GMT +8. The payload came from a Sigfox device.

Thank you

Well momentJs is now available in JSONata if you are using the latest version of Node-RED. Or there is the node-red-contrib-moment node. You could also try the native JavaScript Date conversions though that may depend on the configuration of the device you are running on.

In addition, worth considering whether you should convert it. While processing date/time values, it is far better and less hassle to keep everything in UTC until the point of display to a real person.

1 Like

Show us the value coming from the sigfox device? (Hint attach a debug node to it to inspect the value)

Is it an epoch? Or a string? Or a date object?

Potentially you don't need to do anything & as @TotallyInformation says, you would normally only do any formatting or conversation at display time.

image

Have a look at this thread, I wrote there how to convert to local timezone.

What do you get if you send the msg through a function node with this code...

msg.payload.datetime = new Date(parseInt(msg.payload.time)*1000);
return msg;

Feed you message through this function then to a debug. Show us what you get.

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