相关Function
computeTime(timestamp: number) {
const dateTypeArr = ['days ago', 'hours ago', 'minutes ago'];
const now = Date.now();
const duration = (now - timestamp) / 1000;
const days = Math.floor(duration / 60 / 60 / 24);
const hours = Math.floor((duration / 60 / 60) % 24);
const mins = Math.floor((duration / 60) % 60);
const seconds = Math.floor(duration % 60);
const timeArr = [days, hours, mins, seconds];
const index = timeArr.findIndex((item) => item > 0);
if (index === timeArr.length - 1 || index === -1)
return 'In few seconds ago';
return `${timeArr[index]} ${dateTypeArr[index]}`;
}
computeTime(timestamp: number) {
const now = Date.now();
const duration = (now - timestamp) / 1000;
const oneHour = 60 * 60;
if (duration >= oneHour) {
return false;
}
return true;
}