kidwon
kidwon

Reputation: 4524

Date parse string in `dd-M-yyyy` format

I need to create new Date from a string in format: dd-M-yyyy

example:

var dateStr = '16-Sep-2012';
var date = new Date(dateStr);

However IE isn't very happy with it and considers date value as NaN. Would somebody recommend me or give me a reliable parser for that? 10x for your kind help, BR

Upvotes: 4

Views: 6798

Answers (1)

jacktheripper
jacktheripper

Reputation: 14219

Use the Date.parse function, and then call the new Date function on that variable. See a live example here.

var date = Date.parse('16-Sep-2012');
var formatted_date = new Date(date);

Using the jQuery globalization plugin, you can parse dates using Globalizaiton.parseDate. The plugin adds support for IE.

Upvotes: 5

Related Questions