Timezone Offset of the dashboard user

Hello to all. I am creating a dashboard where with two date pickers and two time pickers, information is extracted from a database by means of an HTTP request. The problem I am having is that the date pickers take into account the time zone. For example, currently my GMT is +5, so if it is already 19:00 and I select a date, January 5th, the timestamp will correspond to January 6th (+5 hours). On the other hand, with the time pickers, I have the opposite problem, where if I select any time, it will come out as entered and will not take into account the offset. My Node-Red is running on an AWS instance, and when I use commands to extract the offset it always gives me +0 or UTC. This dashboard must be able to be used anywhere in the world, so I can't count on the +5 data from my current country, so I need some way to know the offset or GMT of the person entering the dashboard.

You can use new Date() in the ui-template node to get the browser time. You can also use getTimezoneOffset() to get time zone.

example when you land on dashboard the template should return iso timestamp and offset in mins

[{"id":"1f94fb5c.5fe375","type":"ui_ui_control","z":"e67b04df66bd0437","name":"","events":"all","x":190,"y":660,"wires":[["12852117.09e36f"]]},{"id":"12852117.09e36f","type":"function","z":"e67b04df66bd0437","name":"","func":"msg.template = `<script>\nvar btime =  new Date();\nthis.scope.send({btime: btime, offset: btime.getTimezoneOffset()});\n</script>`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":700,"wires":[["9e7f00ae.6ac08"]]},{"id":"9e7f00ae.6ac08","type":"ui_template","z":"e67b04df66bd0437","group":"2d4fe667.28f8ba","name":"","order":5,"width":0,"height":0,"format":"","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","className":"","x":490,"y":640,"wires":[["2ca4bfc8.35ce5"]]},{"id":"2ca4bfc8.35ce5","type":"debug","z":"e67b04df66bd0437","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":620,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

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