// 計算日期
function
_calculatedate
(wantdate);
var currenttime = new
date();
// 今日
var currentdate = timestamp2string(currenttime);
if (wantdate == "thisday")
//alert(currentdate);
// 昨日
var lastdate = timestamp2string(_adddate('4','-1',currenttime));
if (wantdate == "lastday")
//alert(lastdate);
var currentweek = _getcurrentweek();
// 本週第一天
var currentweekfirstdate = timestamp2string(currentweek[0]);
//alert(currentweekfirstdate)
// 本週最後一天
var currentweekenddate = timestamp2string(currentweek[1]);
//alert(currentweekenddate)
if (wantdate == "thisweek")
// 上週第一天
var lastweekfirstdate = timestamp2string(_adddate('4','-7',currentweek[0]));
//alert(lastweekfirstdate)
// 上週最後一天
var lastweekenddate = timestamp2string(_adddate('4','-1',currentweek[0]));
//alert(lastweekenddate)
if (wantdate == "lastweek")
// 前兩周第一天
var last2weekfirstdate = timestamp2string(_adddate('4','-14',currentweek[0]));
if (wantdate == "last2week")
var datepartarray = currentdate.split('-');
// 本月開始的第一天
var curmonthfirstday = new
date(datepartarray[0],datepartarray[1]-1);
var curmonthfirstdate = timestamp2string(curmonthfirstday);
//alert(curmonthfirstdate);
//下月開始的第一天
var nextmonthfirstday = _adddate('5','1',curmonthfirstday);
//本月最後一天
var curmonthendday = new
date(nextmonthfirstday.gettime()-1);
var curmonthenddate = timestamp2string(curmonthendday);
//alert(curmonthenddate);
if (wantdate == "thismonth")
// 上月開始的第一天
var lastmonthfirstday = _adddate('5','-1',curmonthfirstday);
var lastmonthfirstdate = timestamp2string(lastmonthfirstday);
//alert(lastmonthfirstdate);
// 上月最後一天
var lastmonthendday = new
date(curmonthfirstday.gettime()-1);
var lastmonthenddate = timestamp2string(lastmonthendday);
//alert(lastmonthenddate);
if (wantdate == "lastmonth")
// 最近三個月的第一天
var last3monthfirstday = _adddate('5','-2',curmonthfirstday);
var last3monthfirstdate = timestamp2string(last3monthfirstday);
if (wantdate == "last3month")
// 最近半年的第一天
var last6monthfirstday = _adddate('5','-5',curmonthfirstday);
var last6monthfirstdate = timestamp2string(last6monthfirstday);
if (wantdate == "last6month")
// 最近一年的第一天
var last12monthfirstday = _adddate('5','-11',curmonthfirstday);
var last12monthfirstdate = timestamp2string(last12monthfirstday);
if (wantdate == "last12month")
//下下月開始的第一天
var nnextfirstday=_adddate('5','2',curfirstday);
//下月最後一天
var nextendday= new
date(nnextfirstday.gettime()-1);
}// 計算本週
function
_getcurrentweek
(); thisweek[0] = monday;
thisweek[1] = sunday;
return thisweek;
}// 日期格式化
function
timestamp2string
(time)
// 日期時間差計算
function
_adddate
(type, numday, vdate)
return date;
}
JQuery 日期運算
如下,功能描述見註解。例項 1.dateoperate 2020 12 16 2,5,12 計算 2020 12 16日期,加上2年,減去5個月,再加12天後的日期 2.dateoperate 2020 12 16 0,0,15 計算 2020 12 16日期,加15天後的日期 格式化日期字串運算操...
JQuery日期外掛程式
jquery是一款非常優秀的指令碼框架,其豐富的控制項使用起來也非常簡單,配置非常靈活。下面做乙個使用日期外掛程式datapicker的例子。4.在html中插入文字域,最好設定成唯讀,不接受使用者的手動輸入,防止格式混亂,以id標記好。5.編寫js 實現最終效果。document ready fu...
JQuery日期外掛程式datepicker的使用
4.在html中插入文字域,最好設定成唯讀,不接受使用者的手動輸入,防止格式混亂,以id標記好。5.編寫js 實現最終效果 document ready function 效果如下圖 這裡只是做了乙個最基本的日期控制項,我們還需要以中文顯示,限制日期選擇範圍等需求,稍微修改js 這裡基本上就滿足我們...