import moment from 'moment';
const computedTime = (TimeStr) => {
const parsedDate = moment(TimeStr);
if (!parsedDate.isValid()) return TimeStr;
const currentTime = moment();
const timeDifferenceInMilliseconds = currentTime.diff(parsedDate);
const timeDifferenceInMinutes = moment.duration(timeDifferenceInMilliseconds).asMinutes();
const timeDifferenceInHours = moment.duration(timeDifferenceInMilliseconds).asHours();
const timeDifferenceInDays = moment.duration(timeDifferenceInMilliseconds).asDays();
if (Math.abs(timeDifferenceInMinutes) < 1) {
return '刚刚';
} else if (Math.abs(timeDifferenceInMinutes) < 60) {
return `${Math.abs(Math.round(timeDifferenceInMinutes))}分钟前`;
} else if (Math.abs(timeDifferenceInHours) < 24) {
return `${Math.abs(Math.round(timeDifferenceInHours))}小时前`;
} else if (Math.abs(timeDifferenceInDays) < 365) {
return parsedDate.format('MM-DD HH:mm:ss');
}
return parsedDate.format('YYYY-MM-DD HH:mm:ss');
};