UTC DateTime to browser DateTime

** A quick example to get browser time inside the editor. **

Details: Inject node injects the current datetime and dashboard ui_template converts that datetime to local time.

** Note **: Node-RED dashboard should be open for this flow to work.

Example use case: I use this flow to convert DateTime coming from the database to local/browser DateTime(for dashboard display).

[{"id":"93163a23.467de8","type":"tab","label":"Return Local Time","disabled":false,"info":""},{"id":"521e5397.fad17c","type":"ui_template","z":"93163a23.467de8","group":"cc6e12ff.c6b14","name":"Return Browser Time","order":2,"width":"0","height":"0","format":"<script>\n(function(scope) {\n  scope.$watch('msg', function(msg) {\n    if (msg) {\n        var d = new Date(msg.payload);\n        msg.payload = d.toLocaleString();\n        scope.send(msg)\n      // Do something when msg arrives\n    }\n  });\n})(scope);\n</script>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":550,"y":240,"wires":[["d4f87d66.975d6"]]},{"id":"35d037ea.7aad58","type":"inject","z":"93163a23.467de8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$now()","payloadType":"jsonata","trigger":true,"x":340,"y":240,"wires":[["521e5397.fad17c"]]},{"id":"d4f87d66.975d6","type":"debug","z":"93163a23.467de8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":240,"wires":[]},{"id":"cc6e12ff.c6b14","type":"ui_group","z":"","name":"Return Browser Time","tab":"5ad38325.23f07c","order":1,"disp":true,"width":"6","collapse":false},{"id":"5ad38325.23f07c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Flow Info

Created 4 years, 2 months ago
Rating:

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • inject (x1)
Other
  • tab (x1)
  • ui_group (x1)
  • ui_tab (x1)
  • ui_template (x1)

Tags

  • time
  • local
  • browser
  • ui_template
  • dashboard
  • editor
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option