Date format question

  • Thread starter Thread starter Olivier Matrot
  • Start date Start date
O

Olivier Matrot

Hello,

I would like to define a date format that displays a datetime according to
the current culture like this :

if locale is 'fr' then date format would be "dd/MM HH:mm"
if locale is 'en' then date format would be "MM/dd HH:mm"
and so on....

But I do not want to manage each locale separately to be sure that month/day
ordering is correct ! How can I do this ?
TIA.
 
Unless you change this,
System::Threading::Thread::CurrentThread->CurrentCulture will give you a
CultureInfo object for the current culture.

You can create new culture objects like this

new System::Globalization::CultureInfo("de-DE")

Once you ha ve this cultureInfo object, you can use it's DateTimeFormat
member which has properties like ShortDatePattern.

Console.WriteLine(new
System.Globalization.CultureInfo("de-DE").DateTimeFormat.ShortDatePattern);

Should return dd.MM.yyyy

CultureInfo as well as DateTimeFormat implement IFormatProvider. Therefore,
you can also use them in String::Format like this:

Console.WriteLine(String.Format(new CultureInfo("en-GB"), "{0}",
DateTime.Now));

HTH

Marcus Heege
 
Back
Top