admin 管理员组

文章数量: 1086019

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?

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?

Share Improve this question edited Feb 24, 2015 at 11:18 georg 215k56 gold badges322 silver badges400 bronze badges asked Feb 24, 2015 at 11:09 ArdavionArdavion 1631 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9
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()]);

本文标签: Date conversion and manipulation in javascript with Arabic monthsStack Overflow