Javascript - reformat date string to ISO8601

I have a string like this:

21.03.2016 23:59

And I need this string converted into a ISO-8601 date-time string:


Is there a simple way to convert this date? I try it whit moment.js but i can't find a function to parse an existing date.



You can also do this without using moment.js. Look code as following:

(new Date("03.21.2016 23:59")).toISOString()

just you need to change your string 21.03.2016 23:59 (dd-mm-yyyy) to 03.21.2016 23:59 (mm-dd-yyyy). You can easily do this by split the date and change the order of split part.

And if you dont want to do this then simply use moment.js as per matthias's answer.


Using moment.js you could do:

var dateString = '21.03.2016 23:59';
var momentDate = moment(dateString, 'DD.MM.YYYY HH:mm');

Here is a fiddle showing this.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.