Poniższy fragment kodu pokazuje, jak uzyskać sformatowany ciąg DD-MM-YYYY z obiektu Date.
var date = new Date();
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString();
var dd = date.getDate().toString();
var mmChars = mm.split('');
var ddChars = dd.split('');
var currentDay = (ddChars[1]?dd:"0"+ddChars[0]) + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + yyyy;
console.log(currentDay);