arabic-datetime-converter
v1.0.2
Published
Convert English dates/times to Arabic with Arabic numerals.
Maintainers
Readme
arabic-datetime-converter
Convert English dates/times to Arabic with Eastern Arabic numerals (٠–٩). Zero runtime dependencies. ESM + CJS. Fully typed.
Features
- Date conversion:
March 22, 2025→٢٢ مارس ٢٠٢٥ - Time conversion:
5:45 PM→٥:٤٥ م(AM → ص, PM → م) - DateTime conversion:
٢٢ مارس ٢٠٢٥ - ٥:٤٥ م - Digits only: Replace 0–9 with ٠–٩ in any string
- Tree-shakeable, TypeScript types, ESM + CJS
Install
npm i arabic-datetime-converter
# or
pnpm add arabic-datetime-converter
# or
yarn add arabic-datetime-converterQuick Start
ESM
import {
convertDateToArabic,
convertTimeToArabic,
convertDateTimeToArabic,
toArabicNumbers,
} from "arabic-datetime-converter";
convertDateToArabic(new Date("2025-03-22")); // "٢٢ مارس ٢٠٢٥"
convertTimeToArabic("5:45 PM"); // "٥:٤٥ م"
convertDateTimeToArabic("November 5, 2025 11:30 AM"); // "٥ نوفمبر ٢٠٢٥ - ١١:٣٠ ص"
toArabicNumbers("Order #12345 on 2025-03-22"); // "Order #١٢٣٤٥ on ٢٠٢٥-٠٣-٢٢"CommonJS
const {
convertDateToArabic,
convertTimeToArabic,
convertDateTimeToArabic,
toArabicNumbers,
} = require("arabic-datetime-converter");API
toArabicNumbers(input: string | number): string
- Replaces Western digits 0–9 with Eastern Arabic digits ٠–٩.
convertDateToArabic(input: Date | string | number): string
- Accepts a
Date, ISO string, or timestamp. Returns Arabic day, month (Arabic name), year with Arabic digits.
- Accepts a
convertTimeToArabic(input: Date | string | number): string
- Accepts a
Dateor time string like"5:45 PM"or"11:30 AM". Returns Arabic digits and meridiem (ص/م).
- Accepts a
convertDateTimeToArabic(input: Date | string | number): string
- Returns
"<date> - <time>"in Arabic.
- Returns
Notes
- Month names mapping: يناير, فبراير, مارس, أبريل, مايو, يونيو, يوليو, أغسطس, سبتمبر, أكتوبر, نوفمبر, ديسمبر
- Meridiem: AM → ص, PM → م
Compatibility
- Works in Node and modern bundlers/frameworks (React, Vue, Angular, Svelte, Next.js, Nuxt, etc.)
- ESM import and CommonJS require both supported
- Types included (
.d.ts) for TypeScript users
Examples
Format today’s date and current time
import {
convertDateToArabic,
convertTimeToArabic,
} from "arabic-datetime-converter";
convertDateToArabic(new Date()); // e.g. "٥ نوفمبر ٢٠٢٥"
convertTimeToArabic(new Date()); // e.g. "١١:٣٠ ص"Convert a mixed string’s digits
import { toArabicNumbers } from "arabic-datetime-converter";
toArabicNumbers("2025/11/05 14:07"); // "٢٠٢٥/١١/٠٥ ١٤:٠٧"License
MIT
