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

Possible return values for (new Date()).toDateString() in JavaScript? - Stack Overflow

programmeradmin0浏览0评论

The return value for (new Date()).toDateString() is "Mon Oct 08 2012". However I can't find ANY documentation anywhere for what the abbreviations for the rest of the days of the week and months are. Are they all just 3 character abbreviations? I'm trying to write a regex.

+1million points for someone who can find the documentation, or even the source code?

The return value for (new Date()).toDateString() is "Mon Oct 08 2012". However I can't find ANY documentation anywhere for what the abbreviations for the rest of the days of the week and months are. Are they all just 3 character abbreviations? I'm trying to write a regex.

+1million points for someone who can find the documentation, or even the source code?

Share Improve this question asked Oct 8, 2012 at 22:52 RobeezyRobeezy 2,4643 gold badges23 silver badges28 bronze badges 1
  • ECMA-262 says the return value is implementation dependent, so it is not documented there. You may find browser vendor specific documentation. – RobG Commented Oct 9, 2012 at 0:00
Add a ment  | 

4 Answers 4

Reset to default 2

Three letter abbreviations with the first letter upper case.

  • Months: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
  • Days: Sun, Mon, Tue, Wed, Thu, Fri, Sat

However, you may want to look into Date.Parse() instead of using a regular expression to parse the date string, depending on what you're doing anyway.

EDIT: Beware that that Date.Parse() is fairly browser dependent. Check out Why does Date.parse give incorrect results?

It's just the standard English language abbreviation for days and months. Just the first 3 letters and the first one capitalized.

From the MDN:

Date instances refer to a specific point in time. Calling toString will return the date formatted in a human readable form in American English

It's not hard to find:

W3Schools: http://www.w3schools./jsref/jsref_todatestring.asp

Mozilla Developer Network: link

Microsoft Developer Network: link

As you can see, all of them converge, its the week day, the month name, both with 3 characters, day of month and full year.

The specification does not define the output of the string:

The contents of the String are implementation-dependent, but are intended to represent the "date" portion of the Date in the current time zone in a convenient, human-readable form.

This might change in the future, but for now, each browser/environment can produce a different output.

发布评论

评论列表(0)

  1. 暂无评论