LiranC LiranC - 1 year ago 74
Javascript Question

converting a date string to ISO 8601 format string and eventually a date object

i'll make it simple ...
getting from a post request a Date string as:

var str = "25/01/2014";

however, when using the Date.parse() function like this:

var date = Date.parse (str);

i am getting a NaN when i'm trying to print it.

what is the recommended way to format such string to a iso-8601 format, or any other way i can convert such string into a Date format?

Answer Source

To say truth your code works in my system. But if you want to be on safe side then split the string and create date object from it.

var a = '25/01/2014';
var b = a.split('/');
var d = new Date(b[2],b[1],b[0]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download