Tarikh
Formatting

Pattern Formatting

Use token patterns when you need exact control over the output and literal text.

Start Here

Use pattern formatting when you already know the exact shape of the date string you want.

Quick Rule

Use { pattern } when you want token replacement.

Use { mode } when you want a formatter that chooses the structure for you.

Example

import { format } from "@coreify/tarikh";

format("2026-03-31", { pattern: "DD MMM YYYY" });
// -> "31 Mar 2026"

format("2026-03-31", { pattern: "DD MMMM YYYY", locale: "bn-BD" });
// -> "৩১ মার্চ ২০২৬"

format(new Date(2026, 2, 31, 15, 4, 9), {
  pattern: "ddd, D MMM YYYY HH:mm:ss"
});
// -> "Tue, 31 Mar 2026 15:04:09"

Useful Tokens

TokenMeaning
dddd / dddWeekday name
MMMM / MMMMonth name
DD / DDay of month
YYYY / YYYear
HH / H24-hour clock
hh / h12-hour clock
mm / mMinutes
ss / sSeconds
A / aMeridiem

Literal Text

If you want text to stay exactly as written, wrap it in square brackets.

format(new Date(2026, 2, 31, 15, 4), { pattern: "[Today at] h:mm a" });
// -> "Today at 3:04 pm"

Good Fit

Use this for custom labels, table cells, export files, and any place where the output format must stay exact.

On this page