# Format moment.js output

**URL:** <https://discourse.nodered.org/t/format-moment-js-output/75972>\
**Category:** General\
**Created:** [2 March 2023 00:29 UTC](https://discourse.nodered.org/t/format-moment-js-output/75972 "2023-03-02T00:29:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richiep](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@richiep](https://discourse.nodered.org/u/richiep)\
**Post date:** [2 March 2023 00:29 UTC](https://discourse.nodered.org/t/format-moment-js-output/75972/1 "2023-03-02T00:29:18Z")

</div>

Hey All,  
I'm working with moment.js to write a time stamp to a txt file. I have it working but  
the output looks like this.

`56o563nt().for56pmt('March 1, 2023 6:56 PM');`

I want it to format like this

` March 1, 2023 6:56 PM`

How can I do this?  
Thanks  
Rich

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [2 March 2023 00:55 UTC](https://discourse.nodered.org/t/format-moment-js-output/75972/2 "2023-03-02T00:55:01Z")

</div>

**Example Flow**

```auto
[{"id":"d259eab47cf07c40","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":4080,"wires":[["9b3f875e6284e0f6"]]},{"id":"9b3f875e6284e0f6","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment().format(\"MMMM D, YYYY hh:mm A\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4080,"wires":[["4e07d54d66d7e4b0"]]},{"id":"4e07d54d66d7e4b0","type":"debug","z":"54efb553244c241f","name":"debug 34","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":4080,"wires":[]}]

```

Information on token formatting with momentjs can be found [here](https://momentjs.com/docs/#/displaying/format/)

---

<div class="post-metadata">

**Author:** ![richiep](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@richiep](https://discourse.nodered.org/u/richiep)\
**Post date:** [2 March 2023 01:02 UTC](https://discourse.nodered.org/t/format-moment-js-output/75972/3 "2023-03-02T01:02:20Z")

</div>

> [@UnborN](#):
>
> ```auto
> [{"id":"d259eab47cf07c40","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":4080,"wires":[["9b3f875e6284e0f6"]]},{"id":"9b3f875e6284e0f6","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment().format(\"MMMM D, YYYY hh:mm A\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4080,"wires":[["4e07d54d66d7e4b0"]]},{"id":"4e07d54d66d7e4b0","type":"debug","z":"54efb553244c241f","name":"debug 34","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":4080,"wires":[]}]
> 
> ```

Thanks it works!

---

<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:** [16 March 2023 01:02 UTC](https://discourse.nodered.org/t/format-moment-js-output/75972/4 "2023-03-16T01:02:52Z")

</div>

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