Convert timestamp to array hours, minutes, day, month, year

Input a timestamp (default is the current timestamp) in milliseconds. The node will output an object of Hours, Minutes, mSeconds, Day, Month and Year.

[{"id":"4b27b7b.36083c8","type":"inject","name":"Force","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":226,"y":684,"z":"995dcaed.11032","wires":[["f7b2e05e.f958f8"]]},{"id":"2f5ae7e2.12b908","type":"debug","name":"output","active":true,"console":"false","complete":"true","x":818,"y":612,"z":"995dcaed.11032","wires":[]},{"id":"47a4278c.65ce68","type":"function","name":"timeConvert","func":"if ( !msg.timestamp ) msg.timestamp = Math.round(+new Date());\n\nvar dt = new Date(msg.timestamp);\nvar msg = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n}\n\nreturn msg;","outputs":1,"x":622,"y":612,"z":"995dcaed.11032","wires":[["2f5ae7e2.12b908"]]},{"id":"f7b2e05e.f958f8","type":"function","name":"set timestamp","func":"msg.timestamp=1376763133 * 1000;\nreturn msg;","outputs":1,"x":410,"y":684,"z":"995dcaed.11032","wires":[["47a4278c.65ce68"]]},{"id":"3bde431b.451a3c","type":"inject","name":"Force","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":226,"y":612,"z":"995dcaed.11032","wires":[["47a4278c.65ce68"]]}]
mathcoll

Flow Info

created 3 years, 1 month ago

Node Types

Core
  • debug (x1)
  • function (x2)
  • inject (x2)

Tags

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