admin管理员组文章数量:1425956
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")
本文标签: Date Casting in JavascriptStack Overflow
版权声明:本文标题:Date Casting in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745448060a2658754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论