# Converting epoch time

**URL:** https://discourse.nodered.org/t/converting-epoch-time/9858
**Category:** General
**Created:** [7 April 2019 09:36 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858 "2019-04-07T09:36:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)
#### Post date: [7 April 2019 09:36 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/1 "2019-04-07T09:36:04Z")

</div>

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?

```auto
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;

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [7 April 2019 10:20 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/2 "2019-04-07T10:20:21Z")

</div>

take a look at [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment)

---

<div class="post-metadata">

### Author: ![jtmoderate876](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jtmoderate876/32/6423_2.png) [@jtmoderate876](https://discourse.nodered.org/u/jtmoderate876)
#### Post date: [7 April 2019 13:11 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/3 "2019-04-07T13:11:12Z")

</div>

So from: [https://www.epochconverter.com/](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;

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/668ad6c952931c2a638adf6348d48b97c5e6ef6e.png)

Is that sort of what you are going for?

```auto
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"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

### Author: ![mshaz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mshaz/32/2294_2.png) [@mshaz](https://discourse.nodered.org/u/mshaz)
#### Post date: [10 July 2020 13:09 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/4 "2020-07-10T13:09:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [10 July 2020 13:25 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/5 "2020-07-10T13:25:09Z")

</div>

> [@mshaz](#):
>
> How do I fix the codes?

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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [10 July 2020 13:25 UTC](https://discourse.nodered.org/t/converting-epoch-time/9858/6 "2020-07-10T13:25:13Z")

</div>


