1.两个时间的时间差
let new_date = new Date(); //新建一个日期对象,默认现在的时间
let old_date = new Date(Time); //设置过去的一个时间点,"yyyy-MM-dd HH:mm:ss"格式化日期
let difftime = (new_date - old_date)/1000; //计算时间差,并把毫秒转换成秒
let days = parseInt(difftime/86400); // 天 24*60*60*1000
let hours = parseInt(difftime/3600)-24*days; // 小时 60*60 总小时数-过去的小时数=现在的小时数
let minutes = parseInt(difftime%3600/60); // 分钟 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
let seconds = parseInt(difftime%60); // 以60秒为一整份 取余 剩下秒数
this.BindTime=days+"天"+hours+"时"+minutes+"分"
2.根据生日判断年
getage(birthday) {
var birthdays = new Date(birthday.replace(/-/g, "/"));
var d = new Date();
var age =
d.getFullYear() -
birthdays.getFullYear() -
(d.getMonth() < birthdays.getMonth() ||
(d.getMonth() == birthdays.getMonth() &&
d.getDate() < birthdays.getDate())
? 1
: 0);
// this.userAge = age;
return age;
}