I have string like "02.09.13"'
I want to format this sting to date. For this i have written code like,
var date = new Date("02.09.13");
alert(date);
It is printing 'NaN'
but this code is working if the string like "02/09/12"
I have string like "02.09.13"'
I want to format this sting to date. For this i have written code like,
var date = new Date("02.09.13");
alert(date);
It is printing 'NaN'
but this code is working if the string like "02/09/12"
For All browsers apart from IE (not sure which versions) your code will work
var date = new Date('02.09.13');
alert(date);
for IE we use :
var date = new Date(Date.parse('02.09.13'.replace(/\./ig, '/')));
alert(date);
If you actually want to parse a date using the format 'dd.mm.yy' It's worth noting the Date object does not do that out of the box. There is a really good Library called moment.js which makes parsing these kind of dates super simple, example below for your date:
moment("02.09.13", "DD.MM.YY");
NaN show only on iE browser where you need correct date time format.
var d = new Date(2011, 01, 07); // yyyy, mm-1, dd
var d = new Date(2011, 01, 07, 11, 05, 00); // yyyy, mm-1, dd, hh, mm, ss
var d = new Date("02/07/2011"); // "mm/dd/yyyy"
var d = new Date("02/07/2011 11:05:00"); // "mm/dd/yyyy hh:mm:ss"
var d = new Date(1297076700000); // milliseconds
var d = new Date("Mon Feb 07 2011 11:05:00 GMT"); // ""Day Mon dd yyyy hh:mm:ss GMT/UTC
Check this blog: JavaScript new Date() Returning NaN in IE or Invalid Date in Safari
Best Regards
havent tried new Date("02.09.13".replace(/\./g, '/'));
// but thinks 13 ~ 1913
For Date {Sat Feb 09 2013 00:00:00 GMT-0800 (Pacific Daylight Time)}
havent tried new Date("02.09.2013".replace(/\./g, '/'));
You need to replace the . with / Like the one given below
var unformattedDate= "02.09.13"
var actDate = unformattedDate.replace(/\./g, '/');
var date = new Date( actDate );
alert(date);
Hope this may help.