Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTimePicker control does not show AM/PM

I'm having a problem with a DateTimePicker control using a custom format which includes the the two-letter A.M./P.M. abbreviation.

Using an "en-US" CultureInfo DateTimeFormat.ShortTimePattern results in "h:mm tt".

But setting this as custom format in a DateTimePicker with the following code:

Dim curCul As CultureInfo = New CultureInfo("en-US")
dtpTime.Format = DateTimePickerFormat.Custom
dtpTime.CustomFormat = curCul.DateTimeFormat.ShortTimePattern

results in only the hour and the minutes being displayed. I however also need the AM/PM part.

Examples:

11:04 AM is displayed as 11:04

2:00 PM is displayed as 2:00

Additional remark: I noticed that the DateTimePicker keeps track of the correct time. If I increase the time (I'm using ShowUpDown = true for this DateTimePicker control) and increase the hour by 12 and save the changes into the database, the AM/PM has changed. So it seems "only" to be an issue about displaying the AM/PM part.

Thanks for any help. Frank

like image 294
FrankE Avatar asked Sep 25 '12 07:09

FrankE


1 Answers

Try this

dtpTime.Format = DateTimePickerFormat.Custom
dtpTime.CustomFormat = "hh:mm tt"
like image 111
Sudhakar B Avatar answered Sep 21 '22 16:09

Sudhakar B