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
| Token | Meaning |
|---|---|
dddd / ddd | Weekday name |
MMMM / MMM | Month name |
DD / D | Day of month |
YYYY / YY | Year |
HH / H | 24-hour clock |
hh / h | 12-hour clock |
mm / m | Minutes |
ss / s | Seconds |
A / a | Meridiem |
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.