做过酒店管理项目都知道,当我们需要实现一个查询未来一周的客房情况时,需要我们自定义设置一周之内的时间间段,从而将未来一周的住店客房的信息展示出来。那么我们该如何实现这个功能呢?下面我们来实现一下:
//获取当前时间
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
return currentdate;
}
function fun_submit() {
var date1 = new Date();
var date2 = new Date(date1);
date2.setDate(date1.getDate() + 6);
var month=date2.getMonth() + 1
var strDate = date2.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var times = date2.getFullYear() + "-" + month + "-" + strDate;
return times;
}
//计算两个时间相隔的天数
function isLeapYear(year) {
if (year % 4 == 0 && ((year % 100 != 0) || (year % 400 == 0))) {
return true;
}
return false;
}
//判断前后两个日期
function validatePeriod(fyear, fmonth, fday, byear, bmonth, bday) {
if (fyear < byear) {
return true;
} else if (fyear == byear) {
if (fmonth < bmonth) {
return true;
} else if (fmonth == bmonth) {
if (fday <= bday) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
效果截图:
这样你就可以实现一个自定义设置一周的时间间段的功能啦。