caiyuqin 11 місяців тому
батько
коміт
88d4b1be8b
1 змінених файлів з 6 додано та 0 видалено
  1. 6 0
      src/utils/dayjs.ts

+ 6 - 0
src/utils/dayjs.ts

@@ -1,6 +1,12 @@
 import dayjs from 'dayjs'
 import 'dayjs/locale/zh-cn'
+import relativeTime from 'dayjs/plugin/relativeTime' // 使用dayjs自带插件
 
 dayjs.locale('zh-cn')
+dayjs.extend(relativeTime) // 导入相对时间插件
+
+export const timestampFormat = (time: number, type?: string) => dayjs(time).format(type || 'YYYY-MM-DD') // YYYY-MM-DD HH:mm:ss
+export const formatTime = (time: any) => dayjs(time).fromNow()
+
 
 export default dayjs