Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my asp.net Arabic website i want to display date in this format الجمعة 01 ذو الحجة 1432هـ - 28 أكتوبر2011م.how to do this please any one help me
Posted
Comments
Amir Mahfoozi 19-Nov-11 5:26am    
It seems that this site doesn't support arabic compatible languages so please edit the month names in my solution. I'm sure you can cope with this problem ;)
Amir Mahfoozi 20-Nov-11 7:18am    
What was the result ?

Hi Shibiny,
Here is one solution :

C#
System.Globalization.DateTimeFormatInfo HDTF = new System.Globalization.CultureInfo("ar-SA", false).DateTimeFormat;
HDTF.Calendar = new System.Globalization.HijriCalendar();
var s = DateTime.Now.ToString("dddd d MMMM yyyy هجري -", HDTF);

System.Globalization.DateTimeFormatInfo GDTF = new System.Globalization.CultureInfo("en-US", false).DateTimeFormat;
GDTF.MonthGenitiveNames = new string[]
                        {
                            "ژانويه", "فوريه", "مارچ", "آپريل", "مي", "جون", "جولاي", "آگست",
                            "سپتامبر", "اكتبر", "نوامبر", "دسامبر", ""
                        };
s = s + DateTime.Now.ToString("d MMMM yyyy ميلادي", GDTF);



Please mark it as an answer or vote it up if it was helpful for you.

Good Luck
 
Share this answer
 
Comments
Mohamed Abdelwahab 6-Jun-13 9:53am    
many thanks :)
Amir Mahfoozi 6-Jun-13 15:40pm    
You're welcome.
The problem is: one of the words you want to use in this format is Arabic name of a months. As far as I heard from out Arabic colleague, using standard .NET format won't generate Arabic month names even if you use Arabic culture as a parameter of System.DataTime.ToString(IFormatProvider), which is a usual way to format time values to specified culture.

That said, you first need to create month names by yourself, create an array of stings representing month names indexed by month number 0..11. You can get month number as System.DataTime.Month - 1. It's the best to store you month numbers in the .resx resource. (In this way, these constants will be globalized, so you will be able to localize it to different cultures later using satellite assemblies.)

You can use the same technique for calculation of other things such as names of a day of a week.

To compose the final string, you need to create a custom date-time format and include the month name in it obtained on previous step.

See:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^] (help on creation of custom format strings here).

—SA
 
Share this answer
 
Try
CultureInfo Class which Provides information about a specific culture, such as the names of the culture, writing system, the calendar used, and how to format dates and sort strings.
have a look there-MSDN-[CultureInfo Class][^]
Further for more reference about Arabic language in .Net This article-MSDN-[Visual Studio .NET® With Arabic Language Support][^] might help you.
 
Share this answer
 
v2
C#
protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            GetData();
            GetMainProgramData();
            string newhigridate = ConvertDateString(DateTime.Now.ToShortDateString(),3);
            string newArabicdate = ConvertDateString(DateTime.Now.ToShortDateString(), 4);

            lbl_Higri.Text = newhigridate;

            lbl_Date.Text = newArabicdate;
        }
}

public static string ConvertDateString(string DATE_INS, Int32 COND)
    {
        string ConvertDateString = "";
        Int32 CurrentDay;
        Int32 CurrentMonth;
        Int32 CurrentYear;
        DateTime DateFrom;
        //
        DateFrom = Convert.ToDateTime(DATE_INS.Trim());
        CurrentDay = DateFrom.Day;
        CurrentMonth = DateFrom.Month;
        CurrentYear = DateFrom.Year;
        if (COND == 1)//form Higri to Georgian من هجرى الى ميلادى
        {
            DateTime ConversionDate;
            ConversionDate = new DateTime(CurrentYear, CurrentMonth, CurrentDay, new HijriCalendar());
            ConvertDateString = ConversionDate.ToString();
        }
        else if (COND == 2) //from Georgian to Higri  من ميلادى الى هجرى
        {
            CultureInfo higri_format = new CultureInfo("ar-SA");
            higri_format.DateTimeFormat.Calendar = new HijriCalendar();
            DateTime CurrentDate;
            DateTime x;
            if (!DateTime.TryParse(DATE_INS, out x))
            {
                ConvertDateString = "";
                return "";
            }
            CurrentDate = Convert.ToDateTime(DATE_INS);
            ConvertDateString = CurrentDate.Date.ToString("dd/MM/yyyy", higri_format);
        }
        else if (COND == 3) //Higri Data and Month in letters التاريخ الهجري و الشهر بالاحرف
        {
            CultureInfo higri_format = new CultureInfo("ar-SA");
            higri_format.DateTimeFormat.Calendar = new HijriCalendar();
            DateTime CurrentDate;
            DateTime x;
            if (!DateTime.TryParse(DATE_INS, out x))
            {
                ConvertDateString = "";
                return "";
            }
            CurrentDate = Convert.ToDateTime(DATE_INS);
            ConvertDateString = CurrentDate.Date.ToString("dd yyyy MMMM", higri_format).Substring(0, 2) + " " + CurrentDate.Date.ToString("dd yyyy MMMM", higri_format).Substring(7) + " " + CurrentDate.Date.ToString("dd yyyy MMMM", higri_format).Substring(3, 4);
           // ConvertDateString = CurrentDate.Date.ToString("dd yyyy MMMM", higri_format);
            CurrentDate.Date.ToString("dddd d MMMM yyyy", higri_format).Substring(0, 7);
        }
        else if (COND == 4) //Georgian Date and Month in letters التاريخ الميلادي و الشهر بالاحرف
        {
            CultureInfo Arabic_format = new CultureInfo("ar-JO");
            Arabic_format.DateTimeFormat.Calendar = new GregorianCalendar();
            //DateTime CurrentDate;
            //DateTime x;
            //if (!DateTime.TryParse(DATE_INS, out x))
            //{
            //    ConvertDateString = "";
            //    return "";
            //}
            DateTime CurrentDate = DateTime.Now;
            ConvertDateString = CurrentDate.Date.Day.ToString(Arabic_format) + " " + CurrentDate.Date.ToString("dd yyyy MMMM", Arabic_format).Substring(7) + " " + CurrentDate.Date.Year.ToString(Arabic_format);
            //ConvertDateString = CurrentDate.ToString("dd MMMM yyyy", System.Globalization.CultureInfo.GetCultureInfo("ar"));
            //ConvertDateString = CurrentDate.Date.ToString("dd yyyy MMMM", Arabic_format);
            
        }
        else if (COND == 5) //Day of week Name in Arabic اليوم بالعربي
        {
            CultureInfo higri_format = new CultureInfo("ar-SA");
            higri_format.DateTimeFormat.Calendar = new HijriCalendar();
            DateTime CurrentDate;
            DateTime x;
            if (!DateTime.TryParse(DATE_INS, out x))
            {
                ConvertDateString = "";
                return "";
            }
            CurrentDate = Convert.ToDateTime(DATE_INS);
            ConvertDateString = CurrentDate.Date.ToString("dddd", higri_format);
            // ConvertDateString = CurrentDate.Date.ToString("dd yyyy MMMM", higri_format);
            
        }
        return ConvertDateString;
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900