# Epoch time conversion to GMT +8

**URL:** https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862
**Category:** General
**Created:** [10 July 2020 16:04 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862 "2020-07-10T16:04:08Z")
**Posts on this page:** 7
**Page:** 1

<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 16:04 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/1 "2020-07-10T16:04:08Z")

</div>

Hi

I got this code from this forum [Converting epoch time](https://discourse.nodered.org/t/converting-epoch-time/9858). How do I convert it to GMT +8. The payload came from a Sigfox device.

Thank you

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7f8af06e79d33512a2caeeb50f50493b4f44a29.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [10 July 2020 16:09 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/2 "2020-07-10T16:09:38Z")

</div>

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.

---

<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 16:31 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/3 "2020-07-10T16:31:26Z")

</div>

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.

---

<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 17:41 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/4 "2020-07-10T17:41:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddeadbc9126544d368bf22a1f1b1b5d563248153.png)

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [10 July 2020 17:54 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/5 "2020-07-10T17:54:35Z")

</div>

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

> [@Formatting times & dates with moment.js examples](https://discourse.nodered.org/t/formatting-times-dates-with-moment-js-examples/29553):
>
> Since node-RED v1.1.0 support for the moment.js date/time library has been added, currently only available for jsonata expressions, but hopefully in time to also be added to the function node. I've included a few examples below, of how Moment can be used to provide date/time functions. Please feel free to add others This is the basic format, which creates a realtime UTC timestamp similar to Sun Jul 05 2020 13:22:30 GMT+0000. [moment] [{"id":"54c46ebe.3b623","type":"change","z":"a444a9ff.e7a…

---

<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 18:11 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/6 "2020-07-10T18:11:37Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [8 September 2020 18:11 UTC](https://discourse.nodered.org/t/epoch-time-conversion-to-gmt-8/29862/7 "2020-09-08T18:11:39Z")

</div>

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