Date format question

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

Marcus Heege

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top