1

Cant seem to find the answer to this so asking it here. I want to use non arabic numbers for the arabic locale is this possible?

const intlDateTimeFormat.format(new Date());
intlDateTimeFormat = new Intl.DateTimeFormat('ar-SA', { month: 'short', day: 'numeric' });
// "٢٠ شوال"

But i want...

const intlDateTimeFormat.format(new Date());
intlDateTimeFormat = new Intl.DateTimeFormat('ar-SA', { something? , month: 'short', day: 'numeric' });
// "01 شوال"

Any suggestions

Tim
  • 3,576
  • 6
  • 44
  • 58

1 Answers1

5

What you are looking for is to format a Date with an Arabic Locale (i.e. Arabic text) but with Latin (English) Numbers (or any other numbering system of your choice).

Please note that when using the Arabic Language locales the numbering system will default to the Arabic-Eastern numbers for ALL Arabic Locales (i.e. the numbers "٠١٢٣٤٥٦٧٨٩" EXCEPT for five (5) Arabic locales that will use the Arabic-Western (Latin) Numbers 0123456789; these are ar-DZ, ar-EH, ar-LY, ar-MA, and ar-TN locales.

As you are using ar-SA for Saudi Arabia the date will default to using the Arabic-Eastern Numbers "٠١٢٣٤٥٦٧٨٩".

You can change to using the Arabic-Western (Latin) Numbers 0123456789 irrespective of the locale used by either:

1. Specify latn as Unicode numbering system in the locale.

new Intl.DateTimeFormat('ar-SA-u-nu-latn',{month:'short',day:'numeric' }).format(new Date());

OR

2. Specify latn as a numbering system options.

new Intl.DateTimeFormat('ar-SA',{month:'short',day:'numeric',numberingSystem:'latn'}).format(new Date());

In either case, you will output an Arabic String but with English (Arabic-Western Numbers).

**There are other numbering systems that you can use**: 
 "arab", "arabext", " bali", "beng", "deva", "fullwide",
 " gujr", "guru", "hanidec", "khmr", " knda", "laoo",
 "latn", "limb", "mlym", " mong", "mymr", "orya",
 "tamldec", " telu", "thai", "tibt".

Here is an example.

console.log(new Intl.DateTimeFormat('ar-SA-u-nu-latn',{month:'short',day:'numeric'}).format(new Date()));


console.log(new Intl.DateTimeFormat('ar-SA',{month:'short',day:'numeric',numberingSystem:'latn'}).format(new Date()));


console.log(new Intl.DateTimeFormat('ar-SA',{dateStyle: 'full',numberingSystem:'latn'}).format(new Date()));
Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42