1.週數:發現週數與現行不符,可以自定週數
$(function () {
self.moveTo(0, 0);
self.resizeTo(screen.availWidth, screen.availHeight);
$("#ContentPlaceHolder1_txt_sDt").datepicker({
dateFormat: 'yy-mm-dd',
showButtonPanel: true,
showOn: "both",
buttonImage: "../image/calendar.gif",
buttonImageOnly: true,
buttonText: "日期",
//default:false
showWeek: true,
//顯示周數的標題
//default""wk"
weekHeader: "W",
//自訂計算周數的方法,
//default datepicker.iso8601Week
calculateWeek: myWeekCalc
});
});
function myWeekCalc(date) {
var checkDate = new Date(date.getTime());
checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay()));
var time = checkDate.getTime();
//設定1月1日
checkDate.setMonth(0);
checkDate.setDate(1);
return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
}
2.取得一周的區間
function GetNowWeekPeriod(Curr) {
// 現在日期
var cDt = Curr.replace(/-/g, '/'); //轉換日期格式
var myDate = new Date(cDt);
// 現在是星期幾,日為0、一為1、二為2、三為3、四為4、五為5、六為6
var myDay = myDate.getDay();
// 設成日為7
//if (myDay == 0) {
// myDay = 7;
//}
var myStartDate = new Date(cDt);
// myStartDate.setDate(myStartDate.getDate() + (0 - (myDay - 1)));
//myDate.setDate(myStartDate.getDate() + (0 - (myDay - 1)));
myDate.setDate(myStartDate.getDate() + (0 - (myDay ))); //// 將日期變成目前禮拜的星期一
var myEndDate = new Date(cDt);
// 將日期變成目前禮拜的星期日
myEndDate.setDate(myEndDate.getDate() + (7 - myDay-1));
$("#ContentPlaceHolder1_txt_sDt").val(myDate.format("yyyy/MM/dd")); //輸出格式
$("#ContentPlaceHolder1_txt_eDt").val(myEndDate.format("yyyy/MM/dd"));//輸出格式
}
});