Date Casting in Javascript - Stack Overflow

alert(new Date("8142012 4:24:34 PM"));Tue Aug 14 2012 16:24:34 GMT+0800 (Malay Peninsula S

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
Add a ment  | 

2 Answers 2

Reset to default 4

How 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")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745448061a4628138.html

相关推荐

  • Date Casting in Javascript - Stack Overflow

    alert(new Date("8142012 4:24:34 PM"));Tue Aug 14 2012 16:24:34 GMT+0800 (Malay Peninsula S

    6小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信