@chatui/core
Version:
The React library for Chatbot UI
28 lines (27 loc) • 856 B
JavaScript
export var oneDayInMs = 24 * 60 * 60 * 1000;
export var padZero = function padZero(t) {
return "".concat(t < 10 ? '0' : '').concat(t);
};
export function parseDateTime(timestamp) {
var date = new Date(timestamp);
return {
year: date.getFullYear(),
month: padZero(date.getMonth() + 1),
day: padZero(date.getDate()),
hours: padZero(date.getHours()),
minutes: padZero(date.getMinutes()),
seconds: padZero(date.getSeconds())
};
}
/**
* 判断是否在24小时内
*/
export function isWithin24Hours(timestamp) {
var now = Date.now();
var timeDiff = Math.abs(timestamp - now);
return timeDiff < oneDayInMs;
}
export function formatExpireTime(timestamp) {
var d = parseDateTime(timestamp);
return "".concat(d.year, ".").concat(d.month, ".").concat(d.day, " ").concat(d.hours, ":").concat(d.minutes, " \u5230\u671F");
}