alert(new Date("8/14/2012 4:24:34 PM"));
Tue Aug 14 2012 16:24:34 GMT+0800 (Malay Peninsula Standard Time)
alert(new Date("14/08/2012 4:31:29 PM"));
Invalid Date
I tried date.parseExact from datejs, it doesn't work.
Is there any other way to cast "14/08/2012 4:31:29 PM" to a Date object?
alert(new Date("8/14/2012 4:24:34 PM"));
Tue Aug 14 2012 16:24:34 GMT+0800 (Malay Peninsula Standard Time)
alert(new Date("14/08/2012 4:31:29 PM"));
Invalid Date
I tried date.parseExact from datejs, it doesn't work.
Is there any other way to cast "14/08/2012 4:31:29 PM" to a Date object?
Share Improve this question asked Aug 14, 2012 at 8:38 Jerry LamJerry Lam 4521 gold badge7 silver badges22 bronze badges 2- "I tried date.parseExact from datejs" - what arguments did you use? Show use the code for this as well – Eric Commented Aug 14, 2012 at 8:42
- date.parseExact("14/08/2012 4:31:29 PM", "dd/MM/yyyy h:mm:ss tt"); – Jerry Lam Commented Aug 14, 2012 at 8:48
2 Answers
Reset to default 4How about a quick swap using a regular expression?
alert(new Date("14/08/2012 4:31:29 PM".replace(/^(\d+)\/(\d+)/,'$2/$1')));
Rather than Date.parseExact have you tried using Date.parse function provided by the datejs library like so
Date.parse("14/08/2012 4:31:29 PM")