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
2 Answers
Reset to default 4From 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'