How to format a date in Arabic with English digits for date and year in JavaScript?

I want the date to be formatted in the following format:

date: 2016-12-04 at الأحد, 4 ديسمبر, 2016

But I get the following. Numbers are converted to Arabic numerals. I want the date and year to be in English:

الأحد, 4 ديسمبر, 2016

I used the following code to format the date in 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); 
+5
source share
2 answers

Found solution Converting date and manipulation in javascript with Arabic months

The modified code to get my desired result 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 
+1
source

Try ar-MA (for Morocco) instead of ar-SA.

+1
source

Source: https://habr.com/ru/post/1260493/


All Articles