I want the date to be formatted in the following format:
date: 2016-12-04 into الأحد، 4 ديسمبر، 2016
But I'm getting the following. The numbers are converted to Arabic numerals. I want the date and year in English numerals:
الأحد، ٤ ديسمبر، ٢٠١٦
I have used the following code to format the date to Arabic.
var date = new Date('2016-12-04');
options = {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric',
};
var dateString = date.toLocaleDateString('ar-SA', options);
alert(dateString);
Short dates are written in "Day/month/year" from; when writing in Arabic and English: For Gregorian calendar: ١٦/١٢/٢٠١٣ميلادي or 16/12/2013.
Found a solution Date conversion and manipulation in javascript with Arabic months
My modified code to get my desired output is as follows.
var date = new Date('2016-12-04');
var months = ["يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو",
"يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"
];
var days = ["اﻷحد", "اﻷثنين", "الثلاثاء", "اﻷربعاء", "الخميس", "الجمعة", "السبت"];
var delDateString = days[date.getDay()] + ', ' + date.getDate() + ' ' + months[date.getMonth()] + ', ' + date.getFullYear();
console.log(delDateString); // Outputs اﻷحد, 4 ديسمبر, 2016
You can use this Locales to specify numbering system.
let date = newDate.toLocaleDateString('ar-EG-u-nu-latn',{weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'});
also check this MDN link to know more about it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With