//加时间
addDay: function () {
var count = this.data.choseDate;
var year = parseInt(count.split("-")[0]);
var month = parseInt(count.split("-")[1]);
var day = parseInt(count.split("-")[2]);
// 日期加
day += 1;
//判断对应的月份,确定该月有多少天
if(month == 4 || month == 6 || month == 9 || month == 11 ){
if (day > 30) {
month += 1;
day = 1;
}
this.getDateTime(day,month,year)
} else if(month == 2){
// 判断闰年
if ( (year%4==0&&year%100!=0) || year%400==0 ){
if (day > 29) {
month += 1;
day = 1;
}
}else{
if (day > 28) {
month += 1;
day = 1;
}
}
this.getDateTime(day,month,year)
}else {
if (day > 31) {
month += 1;
day = 1;
if (month > 12) {
year += 1;
month = 1
}
}
this.getDateTime(day,month,year)
}
},
//减日期
subtractDay: function () {
var count = this.data.choseDate;
var year = parseInt(count.split("-")[0]);
var month = parseInt(count.split("-")[1]);
var day = parseInt(count.split("-")[2]);
day -= 1;
this.setData({
rightSign: true,
})
// //判断对应的月份,确定该月有多少天
if (day < 1) {
month -= 1;
//判断对应的月份,确定该月有多少天
if(month == 4 || month == 6 || month == 9 || month == 11 ){
day = 30;
this.getDateTime(day,month,year)
}else if(month == 2){
// 判断闰年
if ( (year%4==0&&year%100!=0) || year%400==0 ){
day = 29;
}else{
day = 28;
}
this.getDateTime(day,month,year)
}else{
day = 31;
if (month < 1) {
year -= 1;
month = 12
}
this.getDateTime(day,month,year)
}
}else {
this.getDateTime(day,month,year)
}
},
// 拼接时间
getDateTime(day,month,year){
if (day < 10) {
if (month < 10) {
var changeDay = year + '-0' + month + '-0' + day
}
if (month >= 10) {
var changeDay = year + '-' + month + '-0' + day
}
}
if (day >= 10) {
if (month < 10) {
var changeDay = year + '-0' + month + '-' + day
}
if (month >= 10) {
var changeDay = year + '-' + month + '-' + day
}
}
//判断日期
this.panduanData(changeDay)
},
判断所选日期是否是今日
//判断今日
panduanToday(){
var nowDate = new Date();
var year = nowDate.getFullYear(), month = nowDate.getMonth() + 1, day = nowDate.getDate();
var nowDay =`${year}/${month}/${day}`;
var selectday = this.data.choseDate.replace(/-/g,"/");//替换字符,变成标准格式
var time = new Date(selectday).getTime(); //选择时间的时间戳
var todayTime = new Date(nowDay).getTime(); // 当天凌晨的时间
var tomorrow = new Date(todayTime + 24 * 60 * 60 * 1000).getTime(); // 明天凌晨的时间
if(time < tomorrow && todayTime <= time){
//time < tomorrow && todayTime <= time 为true
console.log('是今日',)
}else{
// console.log('非今日')
}
},
判断所选日期是否是昨日
// 判断昨日
panduanYesterday(){
var nowDate = new Date();
var year = nowDate.getFullYear(), month = nowDate.getMonth() + 1, day = nowDate.getDate();
var nowDay =`${year}/${month}/${day}`;
var todayTime = new Date(nowDay).getTime(); // 当天凌晨的时间
var choseDateFormate = this.data.choseDate.replace(/-/g,"/");//替换字符,变成标准格式
var time = new Date(choseDateFormate).getTime(); //选择的时间
var yesterdayTime = new Date(todayTime - 24 * 60 * 60 * 1000).getTime(); // 昨天凌晨的时间
// console.log('判断是否为昨日',time < todayTime && yesterdayTime <= time)
if(time < todayTime && yesterdayTime <= time){
// time < todayTime && yesterdayTime <= time 为true
console.log('是昨日')
}else{
//非昨日
}
},