Download vetcopilot-app/src/utils/dateUtils.ts from WWsCa/VetNet-LCPS: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/WWsCa/VetNet-LCPS/resolve/main/vetcopilot-app/src/utils/dateUtils.ts
- Command line
-
hf download hf://WWsCa/VetNet-LCPS/vetcopilot-app/src/utils/dateUtils.ts
-
curl -L -o dateUtils.ts https://huggingface.co/WWsCa/VetNet-LCPS/resolve/main/vetcopilot-app/src/utils/dateUtils.ts
1.39 kB
| import { useTranslation } from '../i18n' | |
| export function useDateFormatter() { | |
| const { locale } = useTranslation() | |
| const dateLocale = (): string => (locale === 'en' ? 'en-US' : 'zh-CN') | |
| const formatDate = (date: Date | string, options?: Intl.DateTimeFormatOptions) => { | |
| const d = typeof date === 'string' ? new Date(date) : date | |
| return d.toLocaleDateString(dateLocale(), options) | |
| } | |
| const formatDateTime = (date: Date | string, options?: Intl.DateTimeFormatOptions) => { | |
| const d = typeof date === 'string' ? new Date(date) : date | |
| return d.toLocaleString(dateLocale(), options) | |
| } | |
| const formatTime = (date: Date | string) => { | |
| const d = typeof date === 'string' ? new Date(date) : date | |
| return d.toLocaleTimeString(dateLocale()) | |
| } | |
| return { formatDate, formatDateTime, formatTime } | |
| } | |
| /** 纯函数版:不需要 hook,传入 locale 即可 */ | |
| export function formatDateStatic(date: Date | string, locale: string, options?: Intl.DateTimeFormatOptions) { | |
| const d = typeof date === 'string' ? new Date(date) : date | |
| return d.toLocaleDateString(locale === 'en' ? 'en-US' : 'zh-CN', options) | |
| } | |
| export function formatDateTimeStatic(date: Date | string, locale: string, options?: Intl.DateTimeFormatOptions) { | |
| const d = typeof date === 'string' ? new Date(date) : date | |
| return d.toLocaleString(locale === 'en' ? 'en-US' : 'zh-CN', options) | |
| } | |