爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.2 KiB

"use strict";
function formatTime(timestamp) {
const currentTime = (/* @__PURE__ */ new Date()).getTime();
const diff = (currentTime - timestamp) / 1e3;
if (diff < 60) {
return `${Math.floor(diff)}秒钟前`;
} else if (diff < 60 * 60) {
return `${Math.floor(diff / 60)}分钟前`;
} else if (diff < 60 * 60 * 24) {
return `${Math.floor(diff / 60 / 60)}小时前`;
} else {
let date = new Date(timestamp);
let month = date.getMonth() + 1;
let day = date.getDate();
let hours = date.getHours();
let minutes = date.getMinutes();
if (month < 9)
month = "0" + month;
if (day < 9)
day = "0" + day;
return `${month}-${day} ${hours}:${minutes}`;
}
}
function formatTime2Date(timestamp) {
if (!timestamp) {
return "1970年01月01日";
}
const date = new Date(timestamp);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}${month}${day}`;
}
const time = {
formatTime,
formatTime2Date
};
exports.time = time;
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/timeUtils.js.map