USing moment.js to format date
HTML
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<span id="date"></span>
JavaScript
/*
using momentjs
*/
//var now = moment().format("YYYY-MM-DD HH:mm:ss");
/*
using Date() functions
*/
var now = new Date();
function formatDateTime(d){
function addZeros(n){
return n < 10 ? '0' + n : '' + n;
}
return addZeros(d.getFullYear()+1)+"-"+ addZeros(d.getMonth()) + "-" + d.getDate() + " " +
addZeros(d.getHours()) + ":" + addZeros(d.getMinutes()) + ":" + addZeros(d.getMinutes());
}
now = formatDateTime(now);
$('#date').append(now);