import 'dayjs/locale/en'; import 'dayjs/locale/zh-cn'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import localeData from 'dayjs/plugin/localeData'; import localizedFormat from 'dayjs/plugin/localizedFormat'; import relativeTime from 'dayjs/plugin/relativeTime'; import updateLocale from 'dayjs/plugin/updateLocale'; import utc from 'dayjs/plugin/utc'; import weekday from 'dayjs/plugin/weekday'; const locale = 'zh-cn'; const thresholds = [ { l: 's', r: 1 }, { l: 'm', r: 1 }, { l: 'mm', r: 59, d: 'minute' }, { l: 'h', r: 1 }, { l: 'hh', r: 47, d: 'hour' }, { l: 'dd', r: 29, d: 'day' }, { l: 'M', r: 1 }, { l: 'MM', r: 11, d: 'month' }, { l: 'y' }, { l: 'yy', d: 'year' }, ]; dayjs.extend(relativeTime, { thresholds }); dayjs.extend(updateLocale); dayjs.updateLocale('zh-cn', { relativeTime: { future: '%s后', past: '%s前', s: '几秒', m: '1分钟', mm: '%d分钟', h: '1小时', hh: '%d小时', d: '1天', dd: '%d天', M: '1个月', MM: '%d个月', y: '一年', yy: '%d年', }, }); dayjs.extend(localizedFormat); dayjs.extend(weekday); dayjs.extend(localeData); dayjs.locale(locale); dayjs.extend(duration); dayjs.extend(utc); export default dayjs;