Vue js获取指定日期到今天的相差天数(数值)
//指定时间大于当前时间为负,指定时间小于当前时间为正dateDiff: function (targetDate) {let date1 = new Date(targetDate);let date2 = new Date();date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());date2 = new
·
//指定时间大于当前时间为正,指定时间小于当前时间为负
dateDiff: function (targetDate) {
let date1 = new Date(targetDate);
let date2 = new Date();
date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
const diff = date1.getTime() - date2.getTime(); //目标时间减去当前时间
const diffDate = diff / (24 * 60 * 60 * 1000);
return diffDate;
},
const diffDate = Math.abs(diff / (24 * 60 * 60 * 1000));//取正数
第二个
* 获取指定日期(字符串类型)到当前时间的天数
* @param {Object} sDate1 格式:2018-01-04
*/
dateDiff : function(sDate1) {
var date2 = new Date();
var date1 = new Date(Date.parse(sDate1.replace(/-/g, "/")));
var iDays = parseInt(Math.abs(date2.getTime()- date1.getTime()) /1000/60/60/24);
return iDays;
},
更多推荐
已为社区贡献60条内容
所有评论(0)