Converting epoch time

Hello

I have the following code in a function node. I am trying to convert string_lastseen into a readable format (string_lastseen = 1554625504). But the date function keeps returning what looks like the current time/date for the AWS machine it is running on.

How do you represent the above mentioned string in a readable date format? Is there a function for this?

var string_lastseen  = Object.values(msg.payload.Items[msg.payload.ScannedCount -1].Time);

var lastseen = Number(string_lastseen)+72000000;
var lastseenpayload = Date(lastseen);


msg.payload = lastseenpayload;

return msg;


take a look at node-red-contrib-moment

So from: https://www.epochconverter.com/

the value 1554625504
in epoch SECONDS represents GMT: Sunday, April 7, 2019 8:25:04 AM

(I imagine that is what you are going for)

and perhaps you would like to add two hours (hence the 7200,000?)
to get that in your node-red function node (javascript) you can do:

var string_lastseen = "1554625504";
var lastseen = 7200000+Number(string_lastseen)*1000;//convert from seconds to milliseconds
and add 2 hours
msg.payload = (new Date(lastseen)).toUTCString();

return msg;

Is that sort of what you are going for?

Here is the snippet:
[
    {
        "id": "d0d30a38.451ae8",
        "type": "tab",
        "label": "Temp",
        "disabled": false,
        "info": ""
    },
    {
        "id": "943a111f.ec936",
        "type": "inject",
        "z": "d0d30a38.451ae8",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 100,
        "y": 160,
        "wires": [
            [
                "b3d73c8e.3c21"
            ]
        ]
    },
    {
        "id": "db9500c2.5a57b",
        "type": "debug",
        "z": "d0d30a38.451ae8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 490,
        "y": 160,
        "wires": []
    },
    {
        "id": "b3d73c8e.3c21",
        "type": "function",
        "z": "d0d30a38.451ae8",
        "name": "",
        "func": "var string_lastseen  = \"1554625504\";\nvar lastseen = 7200000+Number(string_lastseen)*1000;//convert from seconds to milliseconds and add 2 hours\nmsg.payload = (new Date(lastseen)).toUTCString();\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 290,
        "y": 160,
        "wires": [
            [
                "db9500c2.5a57b"
            ]
        ]
    }
]

Hi,

Thanks for the codes. I m getting data from Sigfox device but the issue is that am in GMT+8 time zone. How do I fix the codes?

Thank you

This is a 1 year old thread and you have supplied far too little information for anyone to really provide you any good help.

Can you please begin a new thread with a relevant title and some examples of your issue, with real numbers, what you get and what you expect to get.

cheers.