Problem with parse a string to DateTime

Hello,
from an application I get the date in the format "20111230T213000Z", how can I convert it in a function to a DateTime object to calculate with it etc.?
var d = new Date('20111230T213000Z') does not work.

Holger

It tends to be time string but somehow proper format is lost .
The string format should be: YYYY-MM-DDTHH:mm:ss.sssZ
If you cant get properly formatted string from source, you need to break this string into parts to make your time object. There is many ways to do this.
As you are already using the function node, so do it by using string extracting methods.
https://www.w3schools.com/js/js_string_methods.asp

Hello hotNipi,
thanks for your fast answer. I tried it:

var d = new Date('2019-02-06T05:00:00.000Z');
var year = d.getYear();  
var month = d.getMonth();

but year is "119" and month ist "1"

Holger

It might be worth re-reading https://www.w3schools.com/js/js_date_methods.asp

1 Like

Yes, it works, thank you very much.
Holger

Also check out the node-red-contrib-moment node if you need a node for date/time conversions and simple calculations.