前端两三问_含真_前端开发者

1、js 获取当前日期星期几

getWeek(time) {
    let weekDay = ["周日","周一", "周二", "周三", "周四", "周五", "周六"];    
    let myDate = new Date(Date.parse(time));  
    return weekDay[myDate.getDay()]
},

console.log(getWeek('2019-09-11')   // 周三

getWeek(time) {
let weekDay = ["周日","周一", "周二", "周三", "周四", "周五", "周六"];
let myDate = new Date(Date.parse(time));
return weekDay[myDate.getDay()]
},

console.log(getWeek('2019-09-11') // 周三

2、iveiw 时间限制今天之前不可选

<Date-picker 
  type="date" 
  :options="pickerOptionsStart" 
></Date-picker>

pickerOptionsStart: {
  disabledDate (time) {
    return time.getTime() < new Date(new Date().toLocaleDateString()).getTime();
  }
}

<Date-picker
type="date"
:options="pickerOptionsStart"
></Date-picker>

pickerOptionsStart: {
disabledDate (time) {
return time.getTime() < new Date(new Date().toLocaleDateString()).getTime();
}
}

3、js 计算某个时间 前 15天 后15天

function GetDateStr(AddDayCount, date, type) { 
		var dd = new Date(date);
		dd.setDate(dd.getDate()+AddDayCount);
		var y = dd.getFullYear(); 
		var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);
		var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();
		if(type){
			if(date === this.oldTime) {
				return '今天'
			} else {
				return d
			}
		} else {
			return y + "-" + m + "-" + d; 
		}
}

GetDateStr(-14, '2019-09-12')  //  2019-08-29 
GetDateStr(14, '2019-09-12')  //  2019-09-26

function GetDateStr(AddDayCount, date, type) {
var dd = new Date(date);
dd.setDate(dd.getDate()+AddDayCount);
var y = dd.getFullYear();
var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);
var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();
if(type){
if(date === this.oldTime) {
return '今天'
} else {
return d
}
} else {
return y + "-" + m + "-" + d;
}
}

GetDateStr(-14, '2019-09-12') // 2019-08-29
GetDateStr(14, '2019-09-12') // 2019-09-26

» 本文来自:前端开发者 » 《前端两三问_含真_前端开发者》
» 本文链接地址:https://www.rokub.com/73276.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!