多语言版:
diffTime(startDate) {
var dateBegin = new Date(startDate);
var dateEnd = new Date();
var diff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
//计算出相差天数
var days = Math.floor(diff / (24 * 3600 * 1000));
//计算出小时数
var leave1 = diff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
var hours = Math.floor(leave1 / (3600 * 1000));
//计算相差分钟数
var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
var minutes = Math.floor(leave2 / (60 * 1000));
//计算相差秒数
var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
var seconds = Math.round(leave3 / 1000);
var returnStr = seconds + this.$t('index.sec');
if (minutes > 0) {
returnStr = minutes + this.$t('index.min');
}
if (hours > 0) {
returnStr = hours + this.$t('index.hours');
}
if (days > 0) {
returnStr = days + this.$t('index.day');
}
return returnStr + this.$t('index.ago');
}
单语言只需要把 变量改成中文。