refactor(account): improve joined time format

This commit is contained in:
三咲智子 2022-11-26 16:34:24 +08:00
parent 1194d56d09
commit b656c6fda2
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
2 changed files with 7 additions and 6 deletions

View file

@ -5,10 +5,11 @@ const { account } = defineProps<{
account: Account
}>()
const createdAt = $computed(() => {
const date = new Date(account.createdAt)
return new Intl.DateTimeFormat('en-US', { month: 'long', day: 'numeric', year: 'numeric' }).format(date)
})
const createdAt = $(useFormattedDateTime(() => account.createdAt, {
month: 'long',
day: 'numeric',
year: 'numeric',
}))
const fields = $computed(() => {
return [

View file

@ -1,7 +1,7 @@
import type { MaybeRef, UseTimeAgoOptions } from '@vueuse/core'
import type { MaybeComputedRef, UseTimeAgoOptions } from '@vueuse/core'
export const useFormattedDateTime = (
value: MaybeRef<string | Date | undefined>,
value: MaybeComputedRef<string | Date | undefined>,
options: Intl.DateTimeFormatOptions = { dateStyle: 'long', timeStyle: 'medium' },
) => {
const formatter = Intl.DateTimeFormat(undefined, options)