// 時間戳轉時間 export const setSecTime = (time) => { // 好比須要這樣的格式 yyyy-MM-dd hh:mm:ss const date = new Date(time * 1000); const Y = date.getFullYear(); const M = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1; const D = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate(); const h = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); const m = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); const s = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(); return `${Y}-${M}-${D} ${h}:${m}:${s}`; };
// 獲取過去多長時間了 export const getTimeInterval = (time) => { const newTime = Date.parse(new Date()) / 1000; const interval = newTime - time; if (interval < 60) return '剛剛'; if (interval < 3600) return `${parseInt(interval / 60, 10)}分鐘之前`; if (interval < 3600 * 24) return `${parseInt(interval / 3600, 10)}小時之前`; if (interval < 3600 * 24 * 30) return `${parseInt(interval / (3600 * 24), 10)}天之前`; return ''; };