Advanced
Internationalization (i18n)
Day.js supports internationalization through locale files that are loaded on demand.
Day.js supports internationalization through locale files that are loaded on demand.
Changing Locale Globally
import 'dayjs/locale/tr'; // import Turkish locale
dayjs.locale('tr');
dayjs('2024-06-15').format('dddd, MMMM D, YYYY');
// "Cumartesi, Haziran 15, 2024"Changing Locale Per Instance
import 'dayjs/locale/de';
import 'dayjs/locale/fr';
dayjs('2024-06-15').locale('de').format('dddd, MMMM D');
// "Samstag, Juni 15"
dayjs('2024-06-15').locale('fr').format('dddd, MMMM D');
// "samedi, juin 15"Available Locales
Day.js supports 100+ locales including:
| Locale | Code | Example Output |
|---|---|---|
| English | en | Saturday, June 15 |
| Turkish | tr | Cumartesi, Haziran 15 |
| German | de | Samstag, Juni 15 |
| French | fr | samedi, juin 15 |
| Spanish | es | sábado, junio 15 |
| Japanese | ja | 土曜日, 6月 15 |
| Chinese (Simplified) | zh-cn | 星期六, 六月 15 |
| Arabic | ar | السبت, يونيو ١٥ |
| Russian | ru | суббота, июня 15 |
Locale Data
import 'dayjs/locale/en';
const localeData = dayjs.localeData();
localeData.months();
// ["January", "February", ..., "December"]
localeData.monthsShort();
// ["Jan", "Feb", ..., "Dec"]
localeData.weekdays();
// ["Sunday", "Monday", ..., "Saturday"]
localeData.weekdaysMin();
// ["Su", "Mo", ..., "Sa"]
localeData.weekdaysShort();
// ["Sun", "Mon", ..., "Sat"]Custom Locale
const customLocale = {
name: 'custom',
weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years',
},
};
dayjs.locale('custom', customLocale);