Converting DateTime to dd/mm/yyyy hh:mm

So I am currently converting DateTime to epoch time when parsing the date, it is doing in the format of mm/dd/yyyy hh:mm. How do I get it to dd/mm/yyyy:
Here is the code so far:
temp.JSON.parse(msg.payload);
node.log(typeof temp)
msg.payload=Date.parse(temp.payload.DateTime)/1000
return msg.

I'm not sure what would be the best way to parse it

Have a look at the moment node. You can feed your time through that and convert it how you like. Alternatively if you want to do it in js then you can use the Date methods such as getMonth() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

No need to install extra nodes, as the change node has $moment() using JSONata expression. here is an example

[{"id":"a284d8c1.e2dd","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$now()","payloadType":"jsonata","x":590,"y":1760,"wires":[["3be8855b.56d692","8a900799.717ad8"]]},{"id":"3be8855b.56d692","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment(payload).tz(\"Europe/London\").format('DD-MM-YYYY HH:mm') \t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":1760,"wires":[["8a900799.717ad8"]]},{"id":"8a900799.717ad8","type":"debug","z":"8d22ae29.7df6d","name":"arrUpdateDate","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":1760,"wires":[]}]
1 Like