[javascript] Where can I find documentation on formatting a date in JavaScript?

All browsers

The most reliable way to format a date with the source format you're using, is to apply the following steps :

  1. Use new Date() to create a Date object
  2. Use .getDate(), .getMonth() and .getFullYear() to get respectively the day, month and year
  3. Paste the pieces together according to your target format

Example :

_x000D_
_x000D_
var date = '2015-11-09T10:46:15.097Z';_x000D_
_x000D_
function format(input) {_x000D_
    var date = new Date(input);_x000D_
    return [_x000D_
       ("0" + date.getDate()).slice(-2),_x000D_
       ("0" + (date.getMonth()+1)).slice(-2),_x000D_
       date.getFullYear()_x000D_
    ].join('/');_x000D_
}_x000D_
_x000D_
document.body.innerHTML = format(date); // OUTPUT : 09/11/2015
_x000D_
_x000D_
_x000D_

(See also this Fiddle).


Modern browsers only

You can also use the built-in .toLocaleDateString method to do the formatting for you. You just need pass along the proper locale and options to match the right format, which unfortunately is only supported by modern browsers (*) :

_x000D_
_x000D_
var date = '2015-11-09T10:46:15.097Z';_x000D_
_x000D_
function format(input) {_x000D_
    return new Date(input).toLocaleDateString('en-GB', {_x000D_
        year: 'numeric',_x000D_
        month: '2-digit',_x000D_
        day: '2-digit'_x000D_
    });_x000D_
}_x000D_
_x000D_
document.body.innerHTML = format(date); // OUTPUT : 09/11/2015
_x000D_
_x000D_
_x000D_

(See also this Fiddle).


(*) According to the MDN, "Modern browsers" means Chrome 24+, Firefox 29+, IE11, Edge12+, Opera 15+ & Safari nightly build