jsは今週の日付を取得します.
1021 ワード
function formOnload()
{
//
var date = new Date();
var this_day = date.getDay(); //
var step_s = -this_day+1; // ( )
if (this_day == 0) {
step_s = -7; //
}
var step_m = 7 - this_day; // ( )
var thisTime = date.getTime();
var monday = new Date(thisTime + step_s * 24 * 3600* 1000);
var sunday = new Date(thisTime + step_m * 24 * 3600* 1000);
//
var starttime = transferDate(monday); // ( )
var endtime = transferDate(sunday); // ( )
document.getElementById("starttime").value = starttime;
document.getElementById("endtime").value = endtime;
}
function transferDate(date) {
var yearTemp = date.getYear();
var monthTemp = date.getMonth()+1;
var dayTemp = date.getDate();
if(parseInt(monthTemp) < 10) {
monthTemp = "0" + monthTemp;
}
if(parseInt(dayTemp) < 10) {
dayTemp = "0" + dayTemp;
}
return yearTemp + "-" + monthTemp + "-" + dayTemp;
}