Tarikh
Reference

Examples

Copy-paste examples for common Tarikh tasks, including formatting, parsing, relative time, defaults, and React output.

Start Here

Use this page when you want a quick code sample instead of a conceptual explanation.

Standard Formatting

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

format("2026-03-31", { preset: "date" });
// -> "31st Mar 2026"

format(new Date(2026, 2, 31, 15, 30), { preset: "dateTime" });
// -> "31st Mar 2026, 15:30"

format(new Date(2026, 2, 31, 15, 30), { preset: "isoLike" });
// -> "2026-03-31 15:30:00"

Global Defaults

import { format, getDefaults, setDefaults } from "@coreify/tarikh";

setDefaults({
  locale: "bn-BD",
  timeZone: "Asia/Dhaka",
  hijriSystem: "islamic-civil",
});

getDefaults();
// -> current package defaults

format("2026-03-31", { preset: "date" });
// -> localized using the configured defaults

Bangla Calendar

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

toBanglaCalendar("2026-03-31");
// -> { day: 17, month: "Chaitra", monthIndex: 12, year: 1432 }

toBanglaCalendar("2026-03-31", { locale: "bn-BD" });
// -> { day: "১৭", month: "চৈত্র", monthIndex: "১২", year: "১৪৩২" }

format("2026-04-14", { mode: "bangla", locale: "bn-BD", format: "spoken" });
// -> "পহেলা বৈশাখ ১৪৩৩ বঙ্গাব্দ"

Hijri Calendar

import { HIJRI_TIME_ZONES, format, toHijriCalendar } from "@coreify/tarikh";

const [defaultHijriZone] = HIJRI_TIME_ZONES;

toHijriCalendar("2026-03-31");
// -> { day: 12, month: "Shawwal", monthIndex: 10, year: 1447 }

toHijriCalendar("2026-03-31", {
  locale: "bn-BD",
  hijriSystem: "islamic-civil",
  timeZone: defaultHijriZone,
});
// -> localized structured output

format("2026-03-31", {
  mode: "hijri",
  locale: "bn-BD",
  hijriSystem: "islamic-umalqura",
});
// -> localized Hijri date string

Parsing

import { parseDate, parseDateDetailed } from "@coreify/tarikh";

parseDate("17 Chaitra 1432", { calendar: "bangla" });
// -> Date

parseDate("31 Mar 26", { strict: true });
// -> null

parseDateDetailed("31 Mar 26", { strict: true });
// -> { success: false, reason: "strict_mismatch", ... }

Relative Time

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

fromNow("2026-03-31T10:00:00Z", {
  baseDate: "2026-03-31T12:00:00Z",
  style: "short",
});
// -> "2h ago"

fromNow(Date.now() - 30000, {
  threshold: { justNow: 60000 },
  locale: "bn-BD",
});
// -> "এইমাত্র"

React

import { Tarikh } from "@coreify/tarikh/react";

const date = "2026-03-31";

<Tarikh value={date} preset="dateTime" />
<Tarikh.Relative value={date} relativeStyle="short" />
<Tarikh.Bangla value={date} locale="bn-BD" />
<Tarikh.Hijri value={date} locale="bn-BD" hijriSystem="islamic-civil" />

Best Use

Pick the section that matches your task, then copy the smallest example that does the job.

On this page