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

javascript - DateJS parsing mystery - Stack Overflow

programmeradmin0浏览0评论

I'm using DateJS to parse user-inputted dates, and getting some strange results.

  1. Date.parse("15 Jan 2010") returns Fri Jan 15 00:00:00 EST 2010 (right)

  2. Date.parse("15-Apr-2010") returns Thu Apr 15 00:00:00 EDT 2010 (right)

  3. Date.parse("15 Apr 2010") returns Thu Apr 1 00:00:00 EDT 2010 (wrong)

As far as I can tell, the d MMM yyyy input format works fine for every month except April and August; in those two cases, it returns the first of the month no matter what day is entered. Is this a bug, or is there a logical explanation I'm missing?

I'm using DateJS to parse user-inputted dates, and getting some strange results.

  1. Date.parse("15 Jan 2010") returns Fri Jan 15 00:00:00 EST 2010 (right)

  2. Date.parse("15-Apr-2010") returns Thu Apr 15 00:00:00 EDT 2010 (right)

  3. Date.parse("15 Apr 2010") returns Thu Apr 1 00:00:00 EDT 2010 (wrong)

As far as I can tell, the d MMM yyyy input format works fine for every month except April and August; in those two cases, it returns the first of the month no matter what day is entered. Is this a bug, or is there a logical explanation I'm missing?

Share Improve this question asked Mar 12, 2010 at 16:55 Herb CaudillHerb Caudill 50k40 gold badges127 silver badges178 bronze badges 1
  • 1 well when I go to the DateJS home page and type in "15 Apr 2010", it sure seems to work ... – Pointy Commented Mar 12, 2010 at 17:09
Add a ment  | 

1 Answer 1

Reset to default 9

Aha: Looks like the version in the "Download" link is a good bit older than the current source. Here's the mit that fixed this bug:

Dan Yoder fixed bug with timeContext pattern where if a date included "april" or "august", the parser thought the 'a' was the beginning of a time part (as in am/pm).

The most recent version of the EN-US script is here: http://code.google./p/datejs/source/browse/trunk/build/date-en-US.js It would be nice if the website linked to this instead of to a zip file that hasn't been updated for a couple of years.

发布评论

评论列表(0)

  1. 暂无评论