document.write(getTimeStamp() + '<br />');
function getTimeStamp() {
var d = new Date();
var s =
leadingZeros(d.getFullYear(), 4) + '-' +
leadingZeros(d.getMonth() + 1, 2) + '-' +
leadingZeros(d.getDate(), 2) + ' ' +
leadingZeros(d.getHours(), 2) + ':' +
leadingZeros(d.getMinutes(), 2) + ':' +
leadingZeros(d.getSeconds(), 2);
return s;
}
function leadingZeros(n, digits) {
var zero = '';
n = n.toString();
if (n.length < digits) {
for (i = 0; i < digits - n.length; i++)
zero += '0';
}
return zero + n;
}
function getTimeStamp() {
var d = new Date();
var s =
leadingZeros(d.getFullYear(), 4) + '-' +
leadingZeros(d.getMonth() + 1, 2) + '-' +
leadingZeros(d.getDate(), 2) + ' ' +
leadingZeros(d.getHours(), 2) + ':' +
leadingZeros(d.getMinutes(), 2) + ':' +
leadingZeros(d.getSeconds(), 2);
return s;
}
function leadingZeros(n, digits) {
var zero = '';
n = n.toString();
if (n.length < digits) {
for (i = 0; i < digits - n.length; i++)
zero += '0';
}
return zero + n;
}