# moment

Moment.js

NPM

string-format

import moment from 'moment'

export function toLocal24Time(data, format = 'YYYY/MM/DD HH:mm:ss') {
  if (!data) return ''
  return moment(data).format(format)
}
export function toLocalDate(data, format = 'YYYY-MM-DD') {
  if (!data) return ''
  return moment(data).format(format)
}

# 相对时间

import moment from 'moment'

export const fromNowTime = (
    data: string, 
    format = 'YYYY/MM/DD A hh:mm:ss'
  ) => {
  if (!data) return ''
  moment.locale('zh-tw')
  return moment(data, format).fromNow()
}

src\filters\index.ts

export { fromNowTime } from '@/utils'

main.ts

import * as filters from '@/filters'

18 小時前

xx.vue

<span>{{ data.createdOn | fromNowTime }}</span>