4

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...

Anshuman Jasrotia
  • 3,135
  • 8
  • 48
  • 81
Bee
  • 59
  • 1
  • 6
  • 2
    Is your *actual* issue how to retrieve the [`CultureInfo`](http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.110%29.aspx) instance for Indonesia? – O. R. Mapper Oct 15 '14 at 07:01
  • possible duplicate of [DateTime and CultureInfo](http://stackoverflow.com/questions/13797727/datetime-and-cultureinfo) – mehmetseckin Oct 15 '14 at 07:08
  • you should use something like: date.ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")); – SmartDev Oct 15 '14 at 07:11

2 Answers2

3

This is what you should use:

lblTglSuratKeluar.Text = suratKeluarc.TglSurat.ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"));
SmartDev
  • 2,802
  • 1
  • 17
  • 22
1

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.

Community
  • 1
  • 1
mehmetseckin
  • 3,061
  • 1
  • 31
  • 43
  • 4
    If you believe the question is a duplicate, then you should mark it as such – Sayse Oct 15 '14 at 07:07
  • "date" => the name 'date' doesnt exist in current context ??? when i change 'date' with 'indoneisanDate' not error, but the return is same = 10 October 2014. not 10 Oktober 2014 – Bee Oct 15 '14 at 07:28
  • I've updated my answer, tested on a console app, gives the expected output. Please test again. – mehmetseckin Oct 15 '14 at 07:34