Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set name of month with indonesian language using Culture types

Tags:

c#

I have a data from DateTime. with output = "10 October 2014". and I want output like this = "10 Oktober 2014".

This is my test code:

lblTglSuratKeluar.Text = suratKeluarc.TglSurat.ToString("dd MMMM yyyy"); //10 October 2014
var A = lblTglSuratKeluar.Text.Substring(3); //October 2014
var B = A.Substring(0, A.Length - 5); //October

=>So, how to use culturestype ??

 CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures &  ~CultureTypes.NeutralCultures);
 string testOutPut = string.Join(Environment.NewLine, cultures.Select(c => String.Format("{0}:  {1}", B, c.DateTimeFormat.GetMonthName(1))).ToArray());

please, help me...

Thanks...

like image 773
Bee Avatar asked Oct 26 '25 03:10

Bee


2 Answers

This is what you should use:

lblTglSuratKeluar.Text = suratKeluarc.TglSurat.ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"));
like image 111
SmartDev Avatar answered Oct 27 '25 19:10

SmartDev


Check out this question.

You should use "id-ID" CultureInfo and parse your string into a DateTime object using the culture info.

// Get the default formatted date
string indonesianDate =  suratKeluarc.TglSurat.ToString();

// Parse the date string using the indonesian cultureinfo
System.Globalization.CultureInfo cultureinfo = new System.Globalization.CultureInfo("id-ID");
DateTime dt = DateTime.Parse(indonesianDate, cultureinfo);

// Get your formatted string.
lblTglSuratKeluar.Text = dt.ToString("dd MMMM yyyy", cultureinfo);

You can find the other culture codes here.

like image 22
mehmetseckin Avatar answered Oct 27 '25 18:10

mehmetseckin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!