Time in Node-Red

Hello,

I’m currently receiving data in Node-RED and simultaneously transferring it to Google Drive for storage. Everything is working fine, but I’m facing an issue with the time format. Node-RED is providing me with a 13-digit value that I can’t easily interpret to understand the date and time. I need help in converting this timestamp to a more readable format, including the day, month, year, and exact time (I know by clicking on Time I can change the format, however, it is just temporary).

I’ve already written Java code in a Function node to extract sensor data from Node-RED and transfer it to a Google Drive sheet, but I’m unsure how to write code to convert the timestamp into a human-readable format.
Thanks

Hi Nasrin,

You will want to use the Date format to convert the timestamp to a human readable string. You can find more information on the Date object and its methods at: Date - JavaScript | MDN

As a side note it is generally advised to store the timestamp and convert it to a human readable value when displaying the information. You can convert a timestamp to a human readable format in sheets using the =EPOCHTODATE() method. Keep in mind JS uses a millisecond epoch and sheets is expecting a full second epoch so you would need to do something like this: =EPOCHTODATE(A1/1000).

2 Likes