elk/composables/time.ts
2022-11-26 11:36:18 +08:00

13 lines
398 B
TypeScript

import type { MaybeRef } from '@vueuse/core'
export const useFormattedDateTime = (
value: MaybeRef<string | Date | undefined>,
options: Intl.DateTimeFormatOptions = { dateStyle: 'long', timeStyle: 'medium' },
) => {
const formatter = Intl.DateTimeFormat(undefined, options)
return computed(() => {
const v = resolveUnref(value)
return v ? formatter.format(new Date(v)) : ''
})
}