最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Date parse string in `dd-M-yyyy` format - Stack Overflow

programmeradmin5浏览0评论

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 remend me or give me a reliable parser for that? 10x for your kind help, BR

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 remend me or give me a reliable parser for that? 10x for your kind help, BR

Share Improve this question edited Oct 29, 2012 at 22:34 jacktheripper 14.3k12 gold badges60 silver badges93 bronze badges asked Oct 29, 2012 at 17:41 kidwonkidwon 4,5245 gold badges30 silver badges46 bronze badges 3
  • 1 code.google./p/datejs/wiki/APIDocumentation – mccannf Commented Oct 29, 2012 at 17:44
  • 1 Check this out: depressedpress./javascript-extensions/dp_dateextensions – techfoobar Commented Oct 29, 2012 at 18:23
  • 10x for your help, both of you – kidwon Commented Oct 30, 2012 at 10:55
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论