//字符串转日期格式,strDate要转为日期格式的字符串
function getDate(strDate){
var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
return date;
}
//测试
alert(getDate("2012-05-09"));
// 字符串转时间
getDateFromString(strDate){
let str = strDate.replace(/-/g, '/');
var date = new Date(str)
return date
},
//根据日期字符串获取当周周一周日时间
getWeekDateFromString(e) {
let date = this.getDateFromString(e)
let today = date.getDay()
if (today == 0) {
today = 7
}
let dateInve = date.getTime()
let dateStart = this.formatDate(new Date(dateInve - 86400 * (today - 0 - 1) * 1000), 'yyyy-MM-dd')
let dateEnd = this.formatDate(new Date(dateInve - 86400 * (today - 6 - 1) * 1000), 'yyyy-MM-dd')
console.log("week:", dateStart, dateEnd)
},
网友评论