I have a flow to process calendar events from this scrape. It will return a local datetime in the form of YYYY-MM-DD HH:mm:ss.
This works for me but limited to "en-US" without modification. Input is ISO
let start = new Date(msg.payload).toLocaleString("en-US", { hour12: false });
let x = start.split(","); //split date and time
let y = x[0].split("/"); // split date
let z = `${y[2]}-${y[1]}-${y[0]}` + x[1]; //new string YYYY-MM-DD HH:mm:ss
msg.payload = z;
return msg;
[{"id":"a9e4921e7027d964","type":"debug","z":"0a325c35fc29f44e","name":"debug 179","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":400,"wires":[]},{"id":"f5dbee9d71387bf9","type":"function","z":"0a325c35fc29f44e","name":"function 18","func":"let start = new Date(msg.payload).toLocaleString(\"en-US\", { hour12: false });\n\nlet x = start.split(\",\"); //split date and time\nlet y = x[0].split(\"/\"); // split date\nlet z = `${y[2]}-${y[1]}-${y[0]}` + x[1]; //new string YYYY-MM-DD HH:mm:ss\n\nmsg.payload = z;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":400,"wires":[["a9e4921e7027d964"]]},{"id":"e971c76b5dc4198c","type":"inject","z":"0a325c35fc29f44e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2024-04-26T20:00:00.000Z","payloadType":"str","x":240,"y":400,"wires":[["f5dbee9d71387bf9"]]}]
I would like to make the code I am using universal so that regardless of the users tz, the datetime is converted to local time in the proper format.
Thanks,
Mike