Date time picker in different countries

R

Rene

I would like to be able to display a date time using the date time picker
where I show the year-month-day-hour-minute-seconds-AM/PM (for example:
1/19/2005 5:50:00 AM).

The problem with the date time picker is that it does not seem to have a
predefined format that will display this information they way I needed to be
displayed. The only available format options are "Long" "Short" and "Time".

I know I can create my own custom format but I would like the format to
display properly in different countries. If I use my custom format then the
date time picker will not reflect the country where the program is being
used.

My current solution (which sucks) is to have two date time picker controls,
one for the Date part (using the build in "Short" format) and one for the
Time part (using the built in "Time" format) but I would like to only have
one.

Could anyone tell me what do I need to do to have the date time picker
display year-month-day-hour-minute-seconds-AM/PM that display correctly in
all of the different countries?

Thanks.
 
C

Claes Bergefall

Check out the DateTimeFormatInfo class. What you
want is short date pattern (d) followed by the long
time pattern (T).

Get the current info using DateTimeFormatInfo.CurrentInfo
and then get the patterns using the ShortDatePattern and
LongTimePattern properties of the current info. Then
set the format of your DTP to custom and set the
CustomFormat string to the concatenation of the strings
you got above.

This should get you a format correctly reflecting the
country settings. The year will always be first, followed by
time, of course, but I suppose that's acceptable

/claes
 
R

Rene

Thanks Claes!

Claes Bergefall said:
Check out the DateTimeFormatInfo class. What you
want is short date pattern (d) followed by the long
time pattern (T).

Get the current info using DateTimeFormatInfo.CurrentInfo
and then get the patterns using the ShortDatePattern and
LongTimePattern properties of the current info. Then
set the format of your DTP to custom and set the
CustomFormat string to the concatenation of the strings
you got above.

This should get you a format correctly reflecting the
country settings. The year will always be first, followed by
time, of course, but I suppose that's acceptable

/claes
 

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