Date/Month display question

  • Thread starter Thread starter Blue Ball
  • Start date Start date
B

Blue Ball

I am using the following to display the month.
Convert.ToDateTime(my_date).ToString("MMMM")

It works by showing the correct month name in english. How do I display
the date in French and German? I don't want to set the whole site
globalization to be French/German, only part of it needs to be translated.
help...
 
Hi Blue Ball,

You need to change your application's CultureInfo.

Thread.CurrentThread.CurrentCulture = new CultureInfo( "th-TH", false );

That would change it to Thaiwanese or something. Replace the "th-TH" with
the german and french cultureinfo names (I forgot what they were).
 
Blue said:
I am using the following to display the month.
Convert.ToDateTime(my_date).ToString("MMMM")

It works by showing the correct month name in english. How do I display
the date in French and German? I don't want to set the whole site
globalization to be French/German, only part of it needs to be translated.
help...

DateTime d = DateTime.Now;
CultureInfo ger = new CultureInfo( "de-DE");
CultureInfo fra = new CultureInfo( "fr-FR");

Console.WriteLine( d.ToString( "MMMM")); // current culture
Console.WriteLine( d.ToString( "MMMM", ger.DateTimeFormat)); // German
Console.WriteLine( d.ToString( "MMMM", fra.DateTimeFormat)); // French

//////// outputs:

March
März
mars
 
Morten Wennevik said:
You need to change your application's CultureInfo.

Thread.CurrentThread.CurrentCulture = new CultureInfo( "th-TH", false );

That would change it to Thaiwanese or something. Replace the "th-TH" with
the german and french cultureinfo names (I forgot what they were).

Changing the culture of the thread is a bad idea, IMO - it leaves you
open to things other than what you want being in the different culture.
Just provide the culture information as another parameter to
DateTime.ToString.

For example:

using System;
using System.Globalization;

class Test
{
static void Main()
{
CultureInfo ci = new CultureInfo("FR-fr");
Console.WriteLine (DateTime.Now.ToString("MMMM", ci));
}
}
 
You are the best Jon. You have been actively replied to the problems on
this group and giving out very good answers. Really appreciate!!
 
Back
Top