Locales
103 locales are available. Format dates in different languages and cultural conventions.
Setting Locale
Section titled “Setting Locale”Instance Locale
Section titled “Instance Locale”Set locale for a specific instance. Affects month names, day names, and ordinal formatting:
const date = daytime('2025-11-15T14:30:45Z')
// English (default)date.locale('en').format('dddd, MMMM Do YYYY')// "Saturday, November 15th 2025"
// Indonesiandate.locale('id').format('dddd, MMMM Do YYYY')// "Sabtu, November 15th 2025"
// Japanesedate.locale('ja').format('dddd, MMMM Do YYYY')// "土曜日, 11月 15th 2025"Get Current Locale
Section titled “Get Current Locale”const date = daytime('2025-11-15').locale('id')const currentLocale = date.locale()// "id"Default Locale
Section titled “Default Locale”Set default locale for all new instances. Existing instances are not affected:
// Set default localedaytime.setDefaultLocale('id')
// Now all new instances use Indonesiandaytime('2025-11-15').format('dddd')// "Sabtu"
// Get default localeconst defaultLocale = daytime.getDefaultLocale()// "id"Available Locales
Section titled “Available Locales”Get list of all available locales:
const locales = daytime.getAvailableLocales()console.log(locales.length)// 103
console.log(locales)// ["en", "id", "ja", "fr", "de", "es", ...]Supported Locales
Section titled “Supported Locales”Daytime supports 103 locales including:
Major Languages
Section titled “Major Languages”- English (
en) - English - Indonesian (
id) - Bahasa Indonesia - Japanese (
ja) - 日本語 - French (
fr) - Français - German (
de) - Deutsch - Spanish (
es) - Español - Portuguese (
pt) - Português - Russian (
ru) - Русский - Chinese (
zh) - 中文 - Korean (
ko) - 한국어 - Italian (
it) - Italiano - Dutch (
nl) - Nederlands - Arabic (
ar) - العربية - Hindi (
hi) - हिन्दी - And 89 more…
Locale-Aware Formatting
Section titled “Locale-Aware Formatting”Locales affect month and day names:
const date = daytime('2025-11-15T14:30:45Z')
// Englishdate.locale('en').format('dddd, MMMM Do YYYY')// "Saturday, November 15th 2025"
// Indonesiandate.locale('id').format('dddd, MMMM Do YYYY')// "Sabtu, November 15th 2025"
// Japanesedate.locale('ja').format('dddd, MMMM Do YYYY')// "土曜日, 11月 15th 2025"
// Frenchdate.locale('fr').format('dddd, MMMM Do YYYY')// "Samedi, Novembre 15th 2025"
// Germandate.locale('de').format('dddd, MMMM Do YYYY')// "Samstag, November 15th 2025"Format Tokens Affected by Locale
Section titled “Format Tokens Affected by Locale”These format tokens are locale-aware:
dddd- Full day name (Saturday, Sabtu, 土曜日)ddd- Short day name (Sat, Sab, 土)MMMM- Full month name (November, November, 11月)MMM- Short month name (Nov, Nov, 11月)
Other tokens remain the same across locales:
YYYY,YY- YearMM,M- Month numberDD,D,Do- DayHH,H,hh,h- Hourmm,m- Minutess,s- Second
Examples
Section titled “Examples”Multi-Language Date Display
Section titled “Multi-Language Date Display”function formatDateForLocale(date: Daytime, locale: string): string { return date.locale(locale).format('dddd, MMMM Do YYYY')}
const date = daytime('2025-11-15')formatDateForLocale(date, 'en')// "Saturday, November 15th 2025"
formatDateForLocale(date, 'id')// "Sabtu, November 15th 2025"
formatDateForLocale(date, 'ja')// "土曜日, 11月 15th 2025"User Preference-Based Formatting
Section titled “User Preference-Based Formatting”function getUserLocale(): string { // Get from user settings, browser, etc. return localStorage.getItem('locale') || 'en'}
const date = daytime('2025-11-15')const userLocale = getUserLocale()console.log(date.locale(userLocale).format('dddd, MMMM Do YYYY'))// Output depends on userLocale settingApplication-Wide Locale
Section titled “Application-Wide Locale”// Set default locale at app startupdaytime.setDefaultLocale('id')
// All instances now use Indonesiandaytime('2025-11-15').format('dddd')// "Sabtu"
daytime('2025-11-16').format('dddd')// "Minggu"Locale Selection UI
Section titled “Locale Selection UI”const supportedLocales = [ { code: 'en', name: 'English' }, { code: 'id', name: 'Bahasa Indonesia' }, { code: 'ja', name: '日本語' }, { code: 'fr', name: 'Français' }]
function formatWithSelectedLocale(date: Daytime, localeCode: string): string { return date.locale(localeCode).format('dddd, MMMM Do YYYY')}
const date = daytime('2025-11-15')supportedLocales.forEach(locale => { console.log(`${locale.name}: ${formatWithSelectedLocale(date, locale.code)}`)})// English: Saturday, November 15th 2025// Bahasa Indonesia: Sabtu, November 15th 2025// 日本語: 土曜日, 11月 15th 2025// Français: Samedi, Novembre 15th 2025Locale Code Format
Section titled “Locale Code Format”Locale codes follow the ISO 639-1 standard (2-letter language codes):
en- Englishid- Indonesianja- Japanesefr- Frenchde- German- etc.
Locale Persistence
Section titled “Locale Persistence”Locale is preserved when chaining:
const date = daytime('2025-11-15') .locale('id') .add(1, 'day') .add(1, 'month') .format('dddd, MMMM')
// Still uses Indonesian localeconsole.log(date)// "Minggu, Desember"Complete Locale List
Section titled “Complete Locale List”To see all 103 available locales, call:
const allLocales = daytime.getAvailableLocales()console.log(allLocales)// Complete list of all supported locale codes