// 时间戳转时间
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 '';
};