Click here to Skip to main content
15,881,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow
i want to get day of the week i my native language or you may say in my Arabic culture
i use
C#
DateTime dt = DateTime.Now;
MessageBox.Show("DayOfWeek=" + dt.Date.DayOfWeek.ToString());

the output of the above lines is
C#
DayOfWeek=  Sunday

so i changed the culture to Arabic/Saudia arabia
and reuse the above code but i am still getting Day of the week as Sunday
i think i should get
C#
DayOfWeek=   الاحد

i have also changed the keyboard language but still unable to get day of the week i arabic
Note day of the week in arabic has diffrent name
see Line A in the following code
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;

namespace ToCodeProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {   string[] strArr;
            //Get current culture of application:
            CultureInfo UsersCulture = Thread.CurrentThread.CurrentCulture;
            MessageBox.Show("The current culture of this application is : " + UsersCulture.Name);
            //We will change this to English/USA
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            MessageBox.Show("The current culture of this application is : " + Thread.CurrentThread.CurrentCulture);
            strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames;
            for (int i = 0; i < 12; i++) MessageBox.Show(strArr[i]);//Jan Feb Mar ...
            strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;// will be written in Arabic like السبت الاحد الاثنيين ....
            for (int i = 0; i < 7; i++) MessageBox.Show(strArr[i]);// Sat Sun Mon ...
            //We will change this to Arabic/Saudia arabia
            //Set current culture of application:
            Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA");
            MessageBox.Show("The current culture of this application is : " + Thread.CurrentThread.CurrentCulture);
            strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames;
            for (int i = 0; i < 12; i++) MessageBox.Show(strArr[i]);//محرم صفر ربيع ...
            strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;// will be written in Arabic like السبت الاحد الاثنيين ....
            for (int i = 0; i < 7; i++) MessageBox.Show(strArr[i]);// السبت الاحد الاثنيين ....<------------Line A
            // change the keyboard language
            //http://www.microsoft.com/middleeast/msdn/WinFormsAndArabic.aspx#_Toc136842137
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(Application.CurrentCulture);//Set language to current culture
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("ar-SA"));// set it to Arabic saudia arabia
            DateTime dt = DateTime.Now;
            MessageBox.Show("DayOfWeek=" + dt.Date.DayOfWeek.ToString());//<-------- i need day of the week in arabic name not in english
        }
    }
}
Posted
Updated 8-Sep-13 8:15am
v4

1 solution

See this http://www.johnkoerner.com/index.php?/archives/15-C-Day-of-Week-Name.html[^]

This will also work
C#
DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("ar-AE"))

Regards..:)
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 8-Sep-13 14:37pm    
As far as I remember from past CodeProject discussion, it won't work in Arabic, if you nee Arabic names (not numbers) of months weeks.
People used to work around this lack of support of the names... OP is recommended to search CodeProject.
—SA
Khalid Sabtan 8-Sep-13 14:55pm    
This works fine
//Set current culture of application:
Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA");
MessageBox.Show("The current culture of this application is : "+ Thread.CurrentThread.CurrentCulture);
strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames;
for (int i = 0; i < 12; i++) MessageBox.Show(strArr[i]);//محرم صفر ربيع ...
strArr = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;// will be written in Arabic like السبت الاحد الاثنيين ....
for (int i = 0; i < 7; i++) MessageBox.Show(strArr[i]);// السبت الاحد الاثنيين ....

MessageBox.Show(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int)
System.DateTime.Now.DayOfWeek]);
MessageBox.Show(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames[(int)
System.DateTime.Now.Month]);
//Many thanks

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