Convert To Milliseconds

Hi all.

I have a time that is in the format of
How do you convert that to milliseconds? Is there a simple function or do I have to pull it appart and get out the indervidual hours etc?

Don’t understand what you mean. Millisecond is a duration unit and what you have is a date (wich is not a duration).
Which milliseconds do you want :

  • milliseconds ellapsed since a specific date to the date you have => timestamp is something to consider
  • milliseconds of the date you have ? You can just cut the text you don’t need in your date !

I need to convert the date and time to milliseconds since 1971 as in I think its called UNIX epoch.

You’ll need to cut your input as : 2019-08-09T05:27:03.648773 because the part “+00:100:” is not recognised.
To cut, use a function node with :

msg.payload = msg.payload.split("+", 1)
return msg;

And then it will be readable by the date/time formatter node.
In output format of this node you will have to setup “XX” to get as output a millisecond timestamp.

Example flow :

[{"id":"4a30f594.1809bc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ea1672e5.e3843","type":"inject","z":"4a30f594.1809bc","name":"","topic":"","payload":"2019-08-09T05:27:03.648773+00:100:","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":340,"wires":[["b878abcc.418958"]]},{"id":"c7e6907b.3b854","type":"moment","z":"4a30f594.1809bc","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Paris","adjAmount":0,"adjType":"days","adjDir":"add","format":"XX","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Paris","x":500,"y":340,"wires":[["bb08ff89.803ef"]]},{"id":"bb08ff89.803ef","type":"debug","z":"4a30f594.1809bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":340,"wires":[]},{"id":"b878abcc.418958","type":"function","z":"4a30f594.1809bc","name":"","func":"msg.payload = msg.payload.split(\"+\", 1)\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":340,"wires":[["c7e6907b.3b854"]]}]


This is as i would do it, maybe not the best solution :wink:

I will give it a go. Thanks

1 Like