# (GMT) Date time specified in HTTP 1.1 protocol

**URL:** <https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593>\
**Category:** General\
**Created:** [15 April 2023 14:40 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593 "2023-04-15T14:40:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [15 April 2023 14:40 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/1 "2023-04-15T14:40:48Z")

</div>

Hello,

For an API Post request I have to add Date and time in a HTTP 1.1. format like:  
Fri, 14 Apr 2023 11:00:46 GMT (+2)  
I tried new Date settings and a Date/Time Formatter, but cannot get it correct.  
Some advice welcome.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [15 April 2023 14:43 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/2 "2023-04-15T14:43:05Z")

</div>

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

---

<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:** [15 April 2023 16:34 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/3 "2023-04-15T16:34:58Z")

</div>

Or in a change node you can use moment.  
e.g.

```auto
[{"id":"3296b4c9d8e5e4c4","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":3060,"wires":[["2d864e63b1d96923"]]},{"id":"2d864e63b1d96923","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t $mo_obj := $moment($$.payload);\t $mo_obj.format(\"ddd, DD MMM YYYY HH:mm:ss [GMT] (\") & $mo_obj.zone()/60 & \")\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":3120,"wires":[["2423ad6be79ae698"]]},{"id":"2423ad6be79ae698","type":"debug","z":"65617ffeb779f51c","name":"debug 264","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":3060,"wires":[]}]

```

JSONata Expression

```auto
(
    $mo_obj := $moment($$.payload);
    $mo_obj.format("ddd, DD MMM YYYY HH:mm:ss [GMT] (") & $mo_obj.zone()/60 & ")"
)

```

May have to work on the the offset, not quite right.

---

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [15 April 2023 17:05 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/4 "2023-04-15T17:05:59Z")

</div>

Thanks this gives me the correct format. Stil have to study on the timezone- offset.

---

<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:** [15 April 2023 18:35 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/5 "2023-04-15T18:35:16Z")

</div>

I think utcOffset may be better

```auto
(
    $mo_obj := $moment($$.payload);
    $mo_offset := $mo_obj.utcOffset() / 60;
    $prefix := $mo_offset > 0 ? "+" : "";
    $mo_obj.format("ddd, DD MMM YYYY HH:mm:ss [GMT] (" & $prefix & $mo_offset & ")") 
)

```

[edit] removed `-` prefix

---

<div class="post-metadata">

**Author:** ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)\
**Post date:** [15 April 2023 18:57 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/6 "2023-04-15T18:57:10Z")

</div>

[TimeZoneApi.io](http://TimeZoneApi.io) has a default API request that will return the timezone from which the call was initated.

---

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [16 April 2023 07:38 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/7 "2023-04-16T07:38:12Z")

</div>

Thank you E1cid. This is perfect.

---

<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:** [30 April 2023 07:39 UTC](https://discourse.nodered.org/t/gmt-date-time-specified-in-http-1-1-protocol/77593/8 "2023-04-30T07:39:13Z")

</div>

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