(GMT) Date time specified in HTTP 1.1 protocol


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.

Have a look at the moment node.

Or in a change node you can use moment.

[{"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

    $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.

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

I think utcOffset may be better

    $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

TimeZoneApi.io has a default API request that will return the timezone from which the call was initated.

1 Like

Thank you E1cid. This is perfect.

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