Examples / Localization
Korean spacing and collapsed ranges
Format Korean dates with Hangul counter spacing, collapsed date ranges, and pre-clock day periods.
Try this
- Click +35 days or type
35into the span input to watch6월appear on the end date once the range crosses into June. - Click +4 days to see
format()collapse the shared year and month into2026년 5월 1일~5일. - Switch the clock to 09:30 so the Korean day period flips from
오후to오전ahead of the hour.
import { configure, date, time } from 'native-dates';
configure({ locale: 'ko' });
const dayInput = document.querySelector('#day');
const span = document.querySelector('#span');
const clock = document.querySelector('#clock');
const output = document.querySelector('#output');
function render() {
const length = Number(span.value);
if (!dayInput.value || !clock.value || !(length >= 1)) { return; }
const day = date(dayInput.value);
const range = day.to(day.plus(length, 'days'));
const periodClock = time(clock.value).format({ hour: 'numeric', minute: '2-digit', hour12: true });
const rows = [
['Full date', ".format('full')", day.format('full')],
['Collapsed range', ".format('long')", range.format('long')],
['Clock with period', 'hour12: true', periodClock],
['Month heading', '.yearMonth.text', day.yearMonth.text],
];
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-span]')) {
button.addEventListener('click', () => {
span.value = button.dataset.span;
render();
});
}
dayInput.addEventListener('input', render);
span.addEventListener('input', render);
clock.addEventListener('input', render);
render();
Starting…
How it works
Unlike Chinese and Japanese, Korean orthography requires a space after each year, month, and day counter. Calling configure({ locale: 'ko' }) once applies that spacing across every .text property and format() call.
Calling range.format('long') collapses the shared year and month across a tilde while keeping 일 on both day numbers. Crossing into a new month brings the end month counter back automatically.
Twelve-hour clocks place Korea’s morning or afternoon marker before the hour. Reading day.yearMonth.text formats clean monthly headings without a trailing day counter.