# Time format conversion

**URL:** <https://discourse.nodered.org/t/time-format-conversion/83184>\
**Category:** General\
**Created:** [25 November 2023 19:03 UTC](https://discourse.nodered.org/t/time-format-conversion/83184 "2023-11-25T19:03:45Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [25 November 2023 20:18 UTC](https://discourse.nodered.org/t/time-format-conversion/83184/4 "2023-11-25T20:18:23Z")

</div>

> [@juntiedt](#):
>
> Sunrise and sunset comes in that format: "Sat Nov 25 2023 19:57:52 GMT+0100" and I need a timestamp of this format in oder to calculate the time difference. (duration of night and day for example).

You can do the calculation in the change node using moment().diff()  
e.g.

```auto
   $moment($$.payload.sunrise).diff($moment($$.payload.sunset), "seconds")	

```

where msg.payload.sunset and sunrise are in format

```auto
{"sunset":"Sat Nov 25 2023 19:57:52 GMT+0100","sunrise":"Sun Nov 26 2023 07:57:52 GMT+0100"}

```

output in seconds

```auto
43200

```

Is this related to your other topic [Problem with moment](https://discourse.nodered.org/t/problem-with-moment/83182)  
If so please do not double post.

---

_[View the full topic](https://discourse.nodered.org/t/time-format-conversion/83184)._
