javascript date to string
You will need to pad with "0" if its a single digit & note getMonth
returns 0..11 not 1..12
function printDate() {
var temp = new Date();
var dateStr = padStr(temp.getFullYear()) +
padStr(1 + temp.getMonth()) +
padStr(temp.getDate()) +
padStr(temp.getHours()) +
padStr(temp.getMinutes()) +
padStr(temp.getSeconds());
debug (dateStr );
}
function padStr(i) {
return (i < 10) ? "0" + i : "" + i;
}
Relying on JQuery Datepicker, but it could be done easily:
var mydate = new Date();
$.datepicker.formatDate('yy-mm-dd', mydate);