# Moment in function node

**URL:** https://discourse.nodered.org/t/moment-in-function-node/84338
**Category:** General
**Created:** [6 January 2024 16:15 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338 "2024-01-06T16:15:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [6 January 2024 16:15 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/1 "2024-01-06T16:15:06Z")

</div>

why does

```auto
let time = moment().tz("Europe/Berlin").format("HH:mm:ss");

```

work in a function node on Node-Red 3.1.0  
and  
not work in a function node on Node-Red 3.1.3

Problem seems to be that moment() is not accessible

---

<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: [6 January 2024 16:36 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/2 "2024-01-06T16:36:40Z")

</div>

Works for me  
Can you confirm that you included the module in **Setup** tab of your Function node

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

**[EDIT]**  
Updated the screenshot as it seems its the `moment-timezone` module that supports tz methods

---

<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: [6 January 2024 16:52 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/3 "2024-01-06T16:52:48Z")

</div>

You use the `change` node that has `moment` built in

```auto
$moment().tz("Europe/Berlin").format("HH:mm:ss")

```

 ![Screenshot 2024-01-06 at 16.52.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/415e45273ea7f837e8e6ad30fe79029d7a118e30.png)

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [6 January 2024 17:06 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/4 "2024-01-06T17:06:20Z")

</div>

it works!  
many thanks

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fa221119a0428375c344b9dd5f2ab7748744543a.png)

---

<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: [6 January 2024 17:27 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/5 "2024-01-06T17:27:53Z")

</div>

Just a reminder that you do not need moment for that. Use the standard INTL library instead.

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [6 January 2024 19:01 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/6 "2024-01-06T19:01:33Z")

</div>

Just a little trail for unified Name Space 🙂

```auto
[{"id":"c3225306b3694491","type":"function","z":"e973a865c2b93001","name":"function 163","func":"let x = {\n \"$schema\": \"Enterprise/Site/Line1/StationA/measurements/_schema\",\n \"title\": \"Measurement Schema for StationA\",\n \"type\": \"object\",\n \"properties\": {\n \"value\": {\n \"description\": \"Temperatur\",\n \"type\": \"number\"\n },\n \"unit\": {\n \"description\": \"The unit of the measurement value\",\n \"type\": \"string\"\n },\n \"timestamp\": {\n \"description\": \"The timestamp of the measurement in ISO 8601 format\",\n \"type\": \"string\"\n }\n },\n \"required\": msg.payload\n}\nreturn {payload:x};","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":260,"wires":[["55146e0d9a4f4c61"]]},{"id":"8aa8656cbb2aee55","type":"inject","z":"e973a865c2b93001","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50.55","payloadType":"num","x":170,"y":260,"wires":[["3e28fb8fde6e0f72"]]},{"id":"55146e0d9a4f4c61","type":"debug","z":"e973a865c2b93001","name":"debug 2508","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]},{"id":"3e28fb8fde6e0f72","type":"function","z":"e973a865c2b93001","name":"time","func":"let time = moment().tz(\"Europe/Berlin\").format(\"DD-MM-YYYY @ HH:mm:ss\");\nreturn { payload: [msg.payload, \"celsius\", time] };","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nif (context.get(\"counter\") === undefined) {\n context.set(\"counter\", 0);\n}","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":310,"y":260,"wires":[["c3225306b3694491"]]}]

```

---

<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: [20 January 2024 19:01 UTC](https://discourse.nodered.org/t/moment-in-function-node/84338/7 "2024-01-20T19:01:41Z")

</div>

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