getFormatTime: function (timestamp) {
var now = this.getUnix(); //当前时间戳 毫秒级
var time = timestamp * 1000; //转为毫秒,如果是毫秒可以去除转换
var today = this.getToDayUnix(); //今天0点时间戳
var year = this.getYearUnix(); // 今年0点时间戳
//由于 timestamp 是秒,所以需要乘以1000
var timer = (now - time) / 1000; //转换为秒级时间戳
var tip = "";
if (Math.floor(timer / 60) <= 0) {
tip = "刚刚";
} else if (Math.floor(timer / 120) <= 0) {
tip = "1分钟前";
} else if (Math.floor(timer / 3600) <= 0) {
tip = Math.floor(timer / 60) + "分钟前";
} else if (Math.floor(timer / 7200) <= 0) {
tip = "1小时前";
} else if (Math.floor(timer / 86400) <= 0) {
tip = Math.floor(timer / 3600) + "小时前";
} else if (timer / 86400 == 1) {
tip = "昨天";
} else if (timer / 86400 <= 7) {
tip = Math.floor(timer / 86400) + "天前";
} else if (timer / 86400 <= 31) {
tip = Math.floor(timer / (86400 * 7)) + "周前";
} else {
//要注意new Date(time) ,time 是毫秒级
tip = this.getLastDate(time);
}
return tip;
},
毫秒级转换时间
最新推荐文章于 2024-07-26 03:15:52 发布