暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

vue获取任意天数之前或之后的日期

Whoooops 2021-07-02
868
methods: {
// 获取当前时间,day为number,getDay(-1):昨天的日期;getDay(0):今天的日期;getDay(1):明天的日期;【以此类推】
getDay(day) {  
var today = new Date();  
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;  
today.setTime(targetday_milliseconds); //注意,这行是关键代码
  
var tYear = today.getFullYear();  
var tMonth = today.getMonth();  
var tDate = today.getDate();  
tMonth = this.doHandleMonth(tMonth + 1);  
tDate = this.doHandleMonth(tDate);  
return tYear + "-" + tMonth + "-" + tDate;
},
doHandleMonth(month) {  
var m = month;  
if (month.toString().length == 1) {  
m = "0" + month;  
}  
return m;
},
},


文章转载自Whoooops,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论