Moment in function node

why does

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

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

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

1 Like

You use the change node that has moment built in

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

it works!
many thanks

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

Just a little trail for unified Name Space :slightly_smiling_face:

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

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