Skip to content Skip to sidebar Skip to footer

Formatting Arabic Date Value To A String: New Date().toLocaleDateString('ar'); => 'ddyyyy/m/'

Why toLocaleDateString with ar locale returns the date string in ddyyyy/m/ format? Is ddyyyy/m/ legit date format in standard Arabic culture? Never seen a format like that. new Dat

Solution 1:

Stored the formated date string in a variable and consoled chars, it is not ddyyyy/mm/, instead there are some special characters in-between. So the actual format is dd/mm/yyyy + right to left chars.

const str = new Date().toLocaleDateString('ar');
for(let i = 0; i < str.length; i++) {console.log(str[i])}

//Output
"1"
"5"
"‏"
"/"
"1"
"‏"
"/"
"2"
"0"
"2"
"1"

JSFiddle: https://jsfiddle.net/tsfahmad/wjq54o1a/

And then I also checked the charCode

str.charCodeAt(i);
49
53
8207 //<- It is right-to-left mark
47
49
8207 // <- Same (https://www.codetable.net/decimal/8207)
47
50
48
50
49

Post a Comment for "Formatting Arabic Date Value To A String: New Date().toLocaleDateString('ar'); => 'ddyyyy/m/'"