native-dates

API / 函数

monthNames() function

返回用于日历表头与下拉菜单的本地化月份和星期标签数组。

import { monthNames, weekdayNames } from 'native-dates'core 14.9 kB min+br

日历标签

两个辅助函数均直接读取核心内置的 Intl 缓存表,且每次调用都返回全新的数组。调用方可以放心地对返回的列表执行 map、slice 或 reverse,不会污染共享状态。

monthNames()

monthNames(style?, locale?): string[]

返回包含 12 个本地化公历月份名称的数组(从一月到十二月)。默认返回全局配置区域下的完整名称。

style'long' | 'short'默认 'long'

完整月份名称(如 'January')或缩写名称(如 'Jan')。

localeLocale

覆盖全局默认配置的 BCP 47 区域标签。

string[]

按索引 0(一月)到 11(十二月)排列的 12 个月份标签。

months.js
import { monthNames } from 'native-dates';

monthNames('short', 'en-US');
// ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

monthNames('long', 'fr-FR').slice(0, 3);
// ['janvier', 'février', 'mars']

weekdayNames()

weekdayNames(style?, firstDay?, locale?): string[]

返回包含 7 个本地化星期标签的数组,并按起始日轮转排列;起始日依次优先取 firstDay、应用全局配置中的 weekStart,或当前区域的每周第一天。

startOf('week') 的周边界与周范围遵循同一套周起始日规则,保证日历表头始终与周网格对齐。在 configure() 中设置的自定义星期标签同样在此生效。

style'short' | 'long' | 'narrow'默认 'short'

缩写标签(如 'Mon')、完整名称(如 'Monday'),或紧凑的单双字母表头(如 'Mo')。

firstDayDayOfWeek

起始英文星期名称,或从 1(周一)到 7(周日)的 ISO 星期编号。

localeLocale

覆盖全局默认配置的 BCP 47 区域标签。

string[]

按 firstDay、全局配置的 weekStart 或区域默认起始日排列的 7 个星期标签。

import { date, weekdayNames } from 'native-dates';

weekdayNames('short', undefined, 'en-US');
// ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

weekdayNames('narrow', undefined, 'en-US');
// ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']

weekdayNames('narrow', undefined, 'pt-BR');
// ['D', 'S', 'T', 'Q', 'Q', 'S', 'S']

weekdayNames('short', 'monday', 'en-US');
// ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

const daysInGrid = date('2026-11-18', { locale: 'en-US' }).range('week').every('day');
daysInGrid[0].format({ weekday: 'short' }); // 'Sun'
编辑此页更新于 2026年11月16日