Skip to content

Date Formats

Handle different date formats in the JavaScript Calendar component.

TokenDescriptionExample
YYYY4-digit year2024
YY2-digit year24
MMMMFull month nameJanuary
MMMShort month nameJan
MMMonth with zero (01-12)01
MMonth (1-12)1
DDDDFull day nameMonday
DDDShort day nameMon
DDDay with zero (01-31)05
DDay (1-31)5
HHHour 24h with zero (00-23)09
HHour 24h (0-23)9
hhHour 12h with zero (01-12)09
hHour 12h (1-12)9
mmMinutes with zero (00-59)05
mMinutes (0-59)5
ssSeconds with zero (00-59)08
sSeconds (0-59)8
AM/PMUppercase meridiemAM
am/pmLowercase meridiemam
RegionFormatExample
USAMM/DD/YYYY12/31/2024
EuropeDD/MM/YYYY31/12/2024
GermanyDD.MM.YYYY31.12.2024
JapanYYYY/MM/DD2024/12/31
ISOYYYY-MM-DD2024-12-31

The calendar accepts ISO strings, Date objects, and Excel serial numbers:

<script>
const { Calendar } = calendarjs;

// ISO string (recommended)
Calendar(document.getElementById('calendar'), {
    type: 'inline',
    value: '2024-01-15'
});

// Date object
Calendar(element, { value: new Date() });

// Excel serial (with numeric: true)
Calendar(element, { value: 45000, numeric: true });
</script>

Set how dates display using the format property:

<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/index.min.js"></script>

<input type="text" id="input" placeholder="Select date" />
<div id="calendar"></div>

<script>
const { Calendar } = calendarjs;

Calendar(document.getElementById('calendar'), {
    input: document.getElementById('input'),
    format: 'MM/DD/YYYY HH:mm',
    time: true
});
</script>
</html>

Use CalendarJS Helpers for format conversion:

import { Calendar, Helpers } from '@calendarjs/ce';
import '@calendarjs/ce/dist/style.css';

// Date to Excel serial
const serialNumber = Helpers.dateToNum(new Date());

// Excel serial to date
const dateString = Helpers.numToDate(serialNumber);

// Current date formatted
const now = Helpers.now();

// Two-digit padding
const month = Helpers.two(5); // "05"