Function: format()
ts
function format(
date,
formatStr,
options?): string;Format a date using a custom format string. 使用自定义格式字符串格式化日期。
Supported tokens: YYYY YY MMMM MMM MM M DD D HH H hh h mm m ss s SSS A a dddd ddd dd d
Parameters
| Parameter | Type |
|---|---|
date | Date |
formatStr | string |
options | FormatOptions |
Returns
string
Example
ts
format(new Date('2024-01-15T10:30:00'), 'YYYY-MM-DD') // => '2024-01-15'
format(new Date('2024-01-15'), 'MMMM D, YYYY', { locale: 'en-US' }) // => 'January 15, 2024'
format(new Date('2024-01-15'), 'YYYY年MM月DD日', { locale: 'zh-CN' }) // => '2024年01月15日'Since
1.0.0