Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date conversion and manipulation in javascript with Arabic months

I want to change an arabic long-form date, i.e.

الخميس 26 فبراير 2015

(Thursday 26th February, 2015)

into a standard date using standard Javascript in order to manipulate the date (add a day), then display via Date.toLocaleDateString() to convert it back, making

2015 الخميس 27 فبراير

(Friday 27th February, 2015)

Is this a case of picking the date string apart, interpreting the arabic text as a month number and creating a new Date() given the numbers, or is there a prototype that converts an arabic date string into a javascript date? What language and optional parameters need to be used for Date.toLocaleDateString() to produce the same format of arabic date, as using 'ar' the numbers are returned in eastern arabic, as opposed to the required western numerals?

like image 246
Ardavion Avatar asked Feb 10 '23 20:02

Ardavion


1 Answers

var months = ["يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو",
              "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];

var days =["اﻷحد","اﻷثنين","الثلاثاء","اﻷربعاء","الخميس","الجمعة","السبت"];

var date = new Date();

console.log("The current month is " + months[date.getMonth()]);
console.log("The current day is " + days[date.getDay()]);
like image 71
Mohamed Hana Avatar answered Feb 13 '23 16:02

Mohamed Hana