Dates are only useful when people can read them. A database may store 2026-11-15T09:44:00Z, but a customer expects to see “Sunday, 15 November” or “15/11/2026, 2:44 pm” depending on where they live and what they are doing. The format() method in Dayjs is the bridge between those two worlds. This guide explains how formatting works, lists the tokens you will use most, shows how to include literal text safely and introduces the plugins that extend the vocabulary.
How Dayjs formatting works
Every Dayjs instance has a format() method. Called without arguments, it returns an ISO 8601 string that includes the local offset, which is ideal for logs and machine-readable output. Called with a pattern, it replaces each recognised token with the matching part of the date and leaves everything else untouched.
import dayjs from 'dayjs'
dayjs('2026-11-15T14:44:00').format()
// '2026-11-15T14:44:00+05:00'
dayjs('2026-11-15T14:44:00').format('DD/MM/YYYY HH:mm')
// '15/11/2026 14:44'
Because instances are immutable, formatting never changes the underlying value. You can format the same instance in several styles, one for a heading and another for a tooltip, without any risk of side effects. If you have not yet added the library to your project, the installation guide covers every option.
The essential Dayjs format tokens
Tokens are case-sensitive, and that sensitivity carries meaning. Upper-case MM represents the month, while lower-case mm represents minutes. Mixing them up is the most common formatting mistake, so it pays to learn the families below.
Years, months and days
YYYYgives a four-digit year such as 2026;YYgives the last two digits.M,MM,MMMandMMMMgive the month as 11, 11, Nov and November respectively, withMMpadding single digits to two.DandDDgive the day of the month, unpadded and padded.d,dd,dddandddddgive the day of the week as a number from 0 to 6, a minimal name, a short name and the full name.
Hours, minutes and seconds
HandHHuse the 24-hour clock;handhhuse the 12-hour clock.Aandaadd the meridiem in upper or lower case, giving PM or pm.m,mm,sandssgive minutes and seconds;SSSgives milliseconds.ZandZZshow the UTC offset as +05:00 or +0500.
Combining tokens into readable patterns
Real interfaces rarely need a single token. They need patterns that suit the context. A few combinations cover most situations:
const d = dayjs('2026-11-15T14:44:09')
d.format('D MMMM YYYY') // '15 November 2026'
d.format('ddd, D MMM') // 'Sun, 15 Nov'
d.format('h:mm A') // '2:44 PM'
d.format('YYYY-MM-DD') // '2026-11-15'
d.format('dddd [at] HH:mm') // 'Sunday at 14:44'
A useful rule of thumb is to match precision to purpose. A blog post date rarely needs the time; a flight departure needs the hour and minute; an audit log needs seconds and an offset. Choosing the least detailed pattern that still answers the reader's question keeps interfaces calm and uncluttered.
Escaping literal text in Dayjs
Any characters that are not tokens pass through unchanged, but letters can be ambiguous. The word “at”, for instance, contains a, which Dayjs would interpret as the meridiem. To include literal words safely, wrap them in square brackets.
dayjs().format('[Today is] dddd')
// 'Today is Sunday'
dayjs().format('YYYY-MM-DD[T]HH:mm:ss')
// '2026-11-15T14:44:09'
The brackets themselves never appear in the output. Escaping is particularly important when building ISO-like strings by hand, where the letter T separates date and time. Forgetting the brackets produces confusing results that can pass unnoticed in testing.
Extra tokens with the AdvancedFormat plugin
The core keeps its token list short to stay small. When you need ordinals, quarters or week numbers, the AdvancedFormat plugin adds them.
import advancedFormat from 'dayjs/plugin/advancedFormat'
dayjs.extend(advancedFormat)
dayjs('2026-11-15').format('Do MMMM') // '15th November'
dayjs('2026-11-15').format('[Q]Q YYYY') // 'Q4 2026'
dayjs().format('X') // Unix timestamp in seconds
dayjs().format('x') // Unix timestamp in milliseconds
AdvancedFormat also introduces k and kk for hours counted from 1 to 24, and tokens for ISO week numbers when combined with the week plugins. Ordinals in particular make editorial dates feel more natural, since “15th November” reads more warmly than “15 November” in many contexts. You can learn more about loading plugins in our plugins guide.
Locale-aware formats with LocalizedFormat
Hard-coding DD/MM/YYYY works well until a visitor from the United States reads 03/04/2026 as the fourth of March rather than the third of April. The LocalizedFormat plugin solves this by offering shorthand tokens whose actual pattern depends on the active locale.
import localizedFormat from 'dayjs/plugin/localizedFormat'
import 'dayjs/locale/en-gb'
dayjs.extend(localizedFormat)
dayjs('2026-11-15T14:44').format('L') // '11/15/2026' (en)
dayjs('2026-11-15T14:44').locale('en-gb').format('L') // '15/11/2026'
dayjs('2026-11-15T14:44').format('LLL') // 'November 15, 2026 2:44 PM'
The shortcuts LT, LTS, L, LL, LLL and LLLL range from a short time to a full date with weekday and time. Lower-case variants such as l and ll give abbreviated forms. Pairing LocalizedFormat with the right locale is the most reliable way to present dates that feel native to every reader; our locales and internationalisation guide explains how to load and switch languages.
Formatting for machines: ISO strings and timestamps
Not every formatted value is meant for human eyes. APIs, databases and caches prefer unambiguous representations. Dayjs offers several dedicated methods for these cases:
toISOString()returns a UTC string such as2026-11-15T09:44:09.000Z, ideal for JSON payloads.valueOf()returns milliseconds since the Unix epoch;unix()returns seconds.toDate()returns a nativeDate, useful when another library expects one.toJSON()is called automatically byJSON.stringifyand produces an ISO string.
Keeping machine formats separate from display formats is a healthy discipline. Store and transmit ISO strings or timestamps, and only convert to human-readable patterns at the very edge of your application, in the component that renders the value.
Practical Dayjs formatting patterns for real interfaces
Below are patterns that appear again and again in production code. Treat them as starting points and adapt them to your design system.
- Article bylines:
D MMMM YYYY, orLLwith LocalizedFormat for international audiences. - Table cells:
DD MMM YYYYkeeps columns aligned while remaining readable. - Event cards:
ddd D MMM, h:mm Agives weekday, date and time in compact form. - File names:
YYYY-MM-DD_HH-mmsorts chronologically and avoids colons, which some systems reject. - Chart axes:
MMM YYfor monthly series,HH:mmfor intraday data.
For timestamps that change meaning as time passes, such as “posted 5 minutes ago”, a fixed pattern is not the right tool. The RelativeTime plugin handles those, and our relative time and durations guide shows how.
Common formatting mistakes and how to avoid them
Three errors account for most formatting bugs. The first is confusing MM with mm, which silently prints minutes where months were intended. The second is using YYYY when the week-based year GGGG is required for ISO week displays, which matters only around New Year but causes real confusion when it does. The third is formatting an invalid date: if parsing failed, format() returns the string “Invalid Date”. Guarding with isValid() before rendering prevents that text from reaching users.
Testing helps too. A small set of unit tests that format fixed dates, including single-digit days, midnight and the last day of the year, catches regressions quickly when someone edits a pattern months later.
Formatting dates inside frameworks
In component-based frameworks, formatting belongs as close to the rendering layer as possible. Keep raw ISO strings or timestamps in your state, and convert them to display text inside the component that shows them. This approach keeps data portable, avoids storing language-specific strings and makes it trivial to change a pattern in one place.
Many teams wrap common patterns in small helper functions, such as formatShortDate(value) or formatDateTime(value). Each helper calls Dayjs with an agreed pattern, which means designers can request a change to the house style and developers can deliver it by editing a single line. Helpers are also easy to unit test, giving confidence that every screen displays dates consistently.
When rendering on the server, remember that the server's time zone may differ from the visitor's. Format in UTC, or in a zone stored with the user's profile, to keep server and browser output identical. The time zones and UTC guide explains this technique alongside the plugins it relies on.
Accessibility and semantic markup
Formatted dates should also be meaningful to assistive technologies and search engines. Wrapping output in a <time> element with a machine-readable datetime attribute, populated with toISOString(), provides an exact value behind the friendly text. Screen readers can then announce the date accurately, and crawlers can interpret it without guessing at your chosen pattern.
Conclusion
Formatting in Dayjs rests on a compact, predictable token system. Learn the year, month, day and time families, escape literal words with square brackets and choose patterns that match the precision your readers need. When the core tokens are not enough, AdvancedFormat adds ordinals and quarters, while LocalizedFormat adapts output to each visitor's conventions. Keep machine formats such as ISO strings separate from display patterns, guard against invalid input and your dates will read clearly in every corner of your interface. The logical companion to formatting is parsing, which our parsing guide explores next.