function humandate(time1, time2) { //var time1 = Date.parse(new Date()) / 1000; var s = time1 - time2; if (s < 0) { s = Math.abs(s); } if (s > 31536000) { return formatDate(new Date(time2 * 1000)); } else if (s > 2592000) { return parseInt(s / 2592000) + '月'; } else if (s > 86400) { return parseInt(s / 86400) + '天'; } else if (s > 3600) { return parseInt(s / 3600) + '小时'; } else if (s > 60) { return parseInt(s / 60) + '分钟'; } else { return parseInt(s) + '秒'; } } exports.humandate = humandate; 引入: const { humandate } = require('../../utils/humandate.js'); humandate('开始时间戳', '结束时间戳')