Examples / Localization
Chinese calendars and day periods
Format Chinese Gregorian dates, pre-clock day periods, traditional lunar months, and Minguo era years from one input.
Try this
- Click Lunar New Year to see February 17, 2026 format as
2026丙午年正月初一with正月for the first lunar month. - Change the clock from 09:30 to 14:30 to watch the day period switch from
上午9:30to下午2:30before the digits. - Compare the
zh-TW-u-ca-rocrow, which counts the same date as year 115 of the Minguo calendar.
import { configure, date } from 'native-dates';
configure({ locale: 'zh-CN' });
const dayInput = document.querySelector('#day');
const clock = document.querySelector('#clock');
const output = document.querySelector('#output');
function render() {
if (!dayInput.value || !clock.value) { return; }
const day = date(dayInput.value);
const moment = day.at(clock.value, 'Asia/Shanghai');
const periodClock = moment.format({ hour: 'numeric', minute: '2-digit', hour12: true });
const rows = [
['Gregorian', ".format('full')", day.format('full')],
['Day period', 'hour12: true', periodClock],
['Civil anniversary', '.monthDay', day.monthDay.format('long')],
['Lunar calendar', 'zh-CN-u-ca-chinese', day.format('long', 'zh-CN-u-ca-chinese')],
['Minguo era', 'zh-TW-u-ca-roc', day.format('long', 'zh-TW-u-ca-roc')],
];
output.innerHTML = rows.map(([label, locale, value]) => `
<li>
<span class="label">${label} <code>${locale}</code></span>
<b>${value}</b>
</li>`).join('');
}
for (const button of document.querySelectorAll('[data-date]')) {
button.addEventListener('click', () => {
dayInput.value = button.dataset.date;
render();
});
}
dayInput.addEventListener('input', render);
clock.addEventListener('input', render);
render();
Starting…
How it works
Calling configure({ locale: 'zh-CN' }) once sets Chinese counters and spacing across every date, clock, and anniversary call. Twelve-hour clocks place the morning or afternoon marker directly before the hour digits.
For recurring civil holidays and birthdays, day.monthDay strips the year and formats concise month-day labels using that configured locale.
Pass an explicit tag only when converting calendars. Passing 'zh-CN-u-ca-chinese' formats stem-branch lunar years with 正月 for the first month, and 'zh-TW-u-ca-roc' counts years on the Minguo calendar while your stored date stays ISO 8601.