How to display Arabic dates in the Gregorian calendar?
Asked Answered
Z

3

5

I have a multilingual ASP.NET site; one of the languages is Arabic (ar-SA). To switch between cultures, I use this code:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Name)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(Name)

When displaying the date of an article, for example, I just do this, and the localization API takes care of everything:

<%#Eval("DatelineDate","{0:d MMMM yyyy}")%>

The problem is that this displays dates using the Hijiri (Islamic) calendar (e.g. the year 2008 is rendered as 1429). The client wants to display the dates using the Gregorian calendar (still rendering the month names and everything else in Arabic, of course). How can I do this?

Zamir answered 11/12, 2008 at 16:32 Comment(0)
Z
11

Answer:

Turns out the ar-SA culture is the only one to use the Hijiri calendar; all the other Arabic cultures use Gregorian. Here are the different date formats in Arabic (a bit messed up because WMD doesn't support seem to support RTL text).

ar-AE 11 ديسمبر 2008 
ar-BH 11 ديسمبر 2008 
ar-DZ 11 ديسمبر 2008 
ar-EG 11 ديسمبر 2008 
ar-IQ 11 كانون الأول 2008 
ar-JO 11 كانون الأول 2008 
ar-KW 11 ديسمبر 2008 
ar-LB 11 كانون الأول 2008 
ar-LY 11 ديسمبر 2008 
ar-MA 11 دجنبر 2008 
ar-OM 11 ديسمبر 2008 
ar-QA 11 ديسمبر 2008 
ar-SA 13 ذو الحجة 1429 
ar-SY 11 كانون الأول 2008 
ar-TN 11 ديسمبر 2008 
ar-YE 11 ديسمبر 2008 

And for what it's worth here's the quick & dirty code I used to generate this list:

    Response.Write("<table width=300px>")
    For Each ci As CultureInfo In (From c As CultureInfo In CultureInfo.GetCultures(CultureTypes.AllCultures) Order By c.Name Where c.Name.StartsWith("ar-"))
        Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(ci.Name)
        Thread.CurrentThread.CurrentUICulture = New CultureInfo(ci.Name)
        Response.Write(String.Format("<tr><td>{0}</td> <td style='direction:rtl;font-size:20px;'>{1:d MMMM yyyy}</td></tr>", ci.Name, Today))

    Next
    Response.Write("</table>")
    Response.End()

More cultures at http://www.massimilianobianchi.info/max/articles/22/UI-culture-list-and-codes.aspx

Zamir answered 11/12, 2008 at 17:20 Comment(1)
Notice the month names: some are English transliterations, others are from French, or even Babylonian.Nodose
N
2

You can just use another Arabic locale, The only difference between them is the Date format...

Nodose answered 25/1, 2009 at 4:38 Comment(1)
This is not a good practice... using another locale misses other locale features.Gigi
G
0

How about using the Unicode LDML?

IMO, It's better to change the calendar while keeping the country locale (SA in your case).

For example:

const date = new Date(); 
date.toLocaleDateString("ar-SA-u-ca-gregory"); // "٧‏/٢‏/٢٠٢٤"
date.toLocaleDateString("ar-SA-u-ca-iso8601"); // "٧‏/٢‏/٢٠٢٤"
date.toLocaleDateString("ar-SA-u-ca-islamic"); // "٢٧‏/٧‏/١٤٤٥ هـ"
date.toLocaleDateString("ar-SA-u-ca-islamic-umalqura"); // "٢٧‏/٧‏/١٤٤٥ هـ"

You can also customize it:

(new Date()).toLocaleDateString("ar-SA-u-ca-iso8601", {
  weekday: "long",
  year: "numeric",
  month: "long",
  day: "numeric",
  timezone: "Asia/Riyadh",
}) // "الأربعاء، ٧ فبراير ٢٠٢٤" 

Add -nu-latn to get Western Arabic numerals:

(new Date()).toLocaleDateString("ar-SA-u-ca-iso8601-nu-latn", {
  weekday: "long",
  year: "numeric",
  month: "long",
  day: "numeric",
  timezone: "Asia/Riyadh",
}) // "الأربعاء، 7 فبراير 2024" 
Gigi answered 7/2 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.