JavaScriptで日付を取得
現在の年を表示
function ShowNowYear() {
var now = new Date();
var year = now.getFullYear();
document.write(year);
}
現在の YYYY-MM-DD HH:MM:SS を取得
regi=new Date();
var yyyy = regi.getYear(); if (yyyy < 2000) { yyyy += 1900; }
var mm = regi.getMonth() + 1; if (mm < 10) { mm = "0" + mm; }
var dd = regi.getDate(); if (dd < 10) { dd = "0" + dd; }
var hh = regi.getHours(); if (hh < 10) { hh = "0" + hh; }
var min = regi.getMinutes(); if (min < 10) { min = "0" + min; }
var ss = regi.getSeconds(); if (ss < 10) { ss = "0" + ss; }
var now_datetime = yyyy + "-" + mm + "-" + dd + " " + hh + ":" + min + ":" + ss;