Parse DateTime string in JavaScript

Parse DateTime string in JavaScript

Does anyone know how to parse date string in required format


Solution 1:



var strDate = "03.09.1979";
var dateParts = strDate.split(".");

var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);

Solution 2:

If you are using jQuery UI, you can format any date with:

        Your date formated: <span id="date1"></span><br/>


var myDate = '30.11.2011';
var parsedDate = $.datepicker.parseDate('', myDate);

$('#date1').text($.datepicker.formatDate('M d, yy', parsedDate));

Solution 3:

We use this code to check if the string is a valid date

var dt = new Date(txtDate.value)
if (isNaN(dt))

Solution 4:


If you use moment.js, you can use “string” + “format” mode

moment(String, String);
moment(String, String, String);
moment(String, String, Boolean);
moment(String, String, String, Boolean);


moment("12-25-1995", "MM-DD-YYYY");

Solution 5:

Use Date object:

var time = Date.parse('02.02.1999');

Give: 917902800000

Solution 6:

I’v been used following code in IE. (IE8 compatible)

var dString = "2013.2.4";
var myDate = new Date( dString.replace(/(\d+)\.(\d+)\.(\d+)/,"$2/$3/$1") );
alert( "my date:"+ myDate );