# Convert OpenWeather epoch time

**URL:** https://discourse.nodered.org/t/convert-openweather-epoch-time/74939
**Category:** General
**Created:** [9 February 2023 13:06 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939 "2023-02-09T13:06:06Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)
#### Post date: [9 February 2023 13:06 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/1 "2023-02-09T13:06:06Z")

</div>

From OpenWeatherMap I get the sunrise ("payload.sunrise") but it is in epoch format (see image). I am unable to program the function node to display the time in human readable format and I have also not been able to do so with the information on this forum.

Can someone help me with the correct code for that function

 ![NR](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/24f1c12fe763290e3ea96ded8f56eb927ce68db6.png)  
node?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [9 February 2023 13:23 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/2 "2023-02-09T13:23:48Z")

</div>

Hi @HaVi

Using a `change` node, you can format out the dates for your objects using JSONata.

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

`$fromMillis(payload.sunrise*1000,'[Y0001]-[M01]-[D01] [H01]:[m01]:00')`

Add a line for each of your date timestamps in the change node

Or if you prefer the `Function` node approch.

```auto
let d = new Date(0);
d.setUTCSeconds(msg.payload.sunrise);
msg.payload.sunrise = d

```

---

<div class="post-metadata">

### Author: ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)
#### Post date: [9 February 2023 14:33 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/3 "2023-02-09T14:33:14Z")

</div>

Thanks for helping Marcus, I chose the function node and it works perfectly!

---

<div class="post-metadata">

### Author: ![stephenn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stephenn/32/66644_2.png) [@stephenn](https://discourse.nodered.org/u/stephenn)
#### Post date: [9 February 2023 14:52 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/4 "2023-02-09T14:52:42Z")

</div>

I use this: [node-red-contrib-moment (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-moment)

---

<div class="post-metadata">

### Author: ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)
#### Post date: [9 February 2023 15:26 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/5 "2023-02-09T15:26:59Z")

</div>

I also wanted to chime in with the moment node. It's one of the first nodes I install on every new install of node-red, if not _the_ first.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [9 February 2023 15:34 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/6 "2023-02-09T15:34:40Z")

</div>

I did once use moment, but it can only process 1 property at a time (unless I'm mistaken)  
So if you have multiple in 1 payload, it will become cumbersome to use.

The op seems to have 2, using the change node is much easier for situations like this.  
Or maybe @TotallyInformation can develop a new one, that can process multiple properties using the more modern lib [Day.js](https://day.js.org/) 😉

---

<div class="post-metadata">

### Author: ![stephenn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stephenn/32/66644_2.png) [@stephenn](https://discourse.nodered.org/u/stephenn)
#### Post date: [9 February 2023 15:44 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/7 "2023-02-09T15:44:36Z")

</div>

> [@marcus-j-davies](#):
>
> it can only process 1 property at a time

i did not know this. I have only tried it one one value at a time

---

<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: [9 February 2023 17:00 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/8 "2023-02-09T17:00:25Z")

</div>

> [@JayDickson](#):
>
> I also wanted to chime in with the moment node. It's one of the first nodes I install on every new install of node-red, if not _the_ first.

Nice to know! Though I'll be the first to admit that it hasn't had any TLC in a long time. Gets the job done though. Really needs replacing with something that uses a more current library since Moment isn't being developed any more. I just don't have time to do it.

> [@marcus-j-davies](#):
>
> I did once use moment, but it can only process 1 property at a time (unless I'm mistaken)  
> So if you have multiple in 1 payload, it will become cumbersome to use.

Yes, it does, though I guess you could run your data through more than one 😁

> [@marcus-j-davies](#):
>
> The op seems to have 2, using the change node is much easier for situations like this.

True.

> [@marcus-j-davies](#):
>
> Or maybe @TotallyInformation can develop a new one, that can process multiple properties using the more modern lib [Day.js](https://day.js.org/) 😉

I would love to have the time. Sadly, I don't. Still if someone did have the time, I'd be more than happy to let them loose on the repo and I'd even help 😉 Probably best to have a new node in the package so that people weren't disrupted by the change.

---

<div class="post-metadata">

### Author: ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)
#### Post date: [11 February 2023 10:34 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/9 "2023-02-11T10:34:14Z")

</div>

Also a nice node to use, thanks for pointing it out. It's good to see how much support there is on the forum!

---

<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: [25 February 2023 10:34 UTC](https://discourse.nodered.org/t/convert-openweather-epoch-time/74939/10 "2023-02-25T10:34:55Z")

</div>

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