Help with Formatting and converting time string

Hey Guys

I have a Time that is being posted by my pool system which i am dragging down from the internet

I end up with a string

2021-02-05T17:59:11.0000000Z from the HTTP request

image

I want to do some maths on this to see if it has been more than 4 hours since the last update

I have successfully fed this into the moment node and can convert it to local time, but i think i also want to get an output in ms since epoch so i can do the maths on it

Any pointers on setting up the moment node for this ??

Craig

What message are you getting?

Is it a timestamp?

Because if it is, all you would need to do is look at the old value and the new value.
If there is more than (4 hours = 240 minutes = 14400 seconds =) 14400000 milliseconds difference.

Just a thought.

It is not a timestamp - it is exactly as i have put above - this is returned to me through an MQTT string from a process that does a Rest API query against a web based datasource.

I have no control of any of that unitl it is received by my MQTT broker.

As you can see in the shot above this is a string of exactly the format as listed.

So what i have done upto now (for display purposes) is to feed that through the moment node and place it into a text object on the dashboard.

What i am wanting to do now is to essentially reverse that and take that string, turn it back into a timestamp in ms and then perform maths on that to enable me to send an alert out.

So in essence the question is - how can i take that string and output a timestamp ?

Craig

In a function node (sorry not the Moment node), date.parse to convert from your string format to date format. Then you can use get.ms or whatever you want to do (eg Date and time)

This should give you the timestamp in ms.

let ms = new Date(msg.payload).getTime()

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