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

What date format is Date().toDateString() in Javascript? - Stack Overflow

programmeradmin0浏览0评论

In W3School's page for toDateString() function , it says when you call toDateString() it will give something like Mon Jan 12 2015. It makes me wonder which date format toDateString() conforms to?

Is it "EEE MMM dd YYYY" or "EEE MMM d YYYY"?

In W3School's page for toDateString() function , it says when you call toDateString() it will give something like Mon Jan 12 2015. It makes me wonder which date format toDateString() conforms to?

Is it "EEE MMM dd YYYY" or "EEE MMM d YYYY"?

Share Improve this question asked Jan 12, 2015 at 1:01 donkeydonkey 4,3637 gold badges45 silver badges69 bronze badges 2
  • Try it out in your browser's console. For me, it's the former (leading zeros) in Chrome on Windows 8.1. i.e.: (new Date(2015, 1, 9)).toDateString() => "Mon Feb 09 2015". – Cᴏʀʏ Commented Jan 12, 2015 at 1:06
  • You'll get a more consistent result from toISOString(), but note that it is not present in IE through version 8. – Mark Reed Commented Jan 12, 2015 at 1:07
Add a ment  | 

2 Answers 2

Reset to default 4

From the ECMAScript 5.1 spec:

15.9.5.3 Date.prototype.toDateString ( )

This function returns a String value. 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.

Therefore, you can't assume any format, it's implementation-dependent.

Here is a good link to Mozilla:

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString

The format follows (when using moment.js): 'EEE MMM d YYYY'

发布评论

评论列表(0)

  1. 暂无评论