Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Browsers either use system settings for date formats, or use their own (often US–centric) settings.</p> <p>There is a <em>Date.prototype.toLocaleDateString()</em> method that should return a date based on current system settings, however it's implementation dependent and completely unreliable due to being inconsistent between browsers.</p> <p>e.g. for me on 13 December, 2011:</p> <ol> <li>Safari returns <code>13 December 2001</code></li> <li>Firefox <code>12/13/2011</code></li> <li>Opera <code>Tuesday December 13, 2011</code></li> <li>Chrome <code>Tuesday, December 13, 2011</code></li> <li>IE 6 <code>Tuesday, 13 December, 2011</code></li> </ol> <p>So only Safari and IE actually use the system settings, it seems the developers of other browsers are either too lazy, indifferent or ignorant to accommodate non–US users. </p> <p>An alternative is to either ask the user what format they prefer, or just use an unambiguous format, e.g. 13-Dec-2011 will be understood by everyone. If you really must use numbers only, then the ISO-8601 format should do fine: 2011-12-13 with the added benefit that it is simple to sort.</p> <p>Some functions that print a short date in the above formats:</p> <pre><code>// format: 2011/12/5 function shortDate1(obj) { obj = obj || new Date(); return obj.getFullYear() + '/' + (obj.getMonth() + 1) + '/' + obj.getDate(); } // format: 2011/12/05 // (padded single digit month and day) function shortDate2(obj) { function z(n) { return (n &lt; 10? '0' : '') + n; } obj = obj || new Date(); return obj.getFullYear() + '/' + z(obj.getMonth() + 1) + '/' + z(obj.getDate()); } // format: 15-Dec-2011 function shortDate3(obj) { obj = obj || new Date(); function z(n) { return (n &lt; 10? '0' : '') + n; } months = ['Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep','Oct','Nov','Dec']; return [z(obj.getDate()),months[obj.getMonth()],obj.getFullYear()].join('-'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload