DateTimePicker control does not show AM / PM

I have a problem with a DateTimePicker control using a custom format that includes a two-letter version of AM / PM abbreviation.

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

But setting this as a 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 

displays only hour and minutes. However, I also need an AM / PM part.

Examples:

11:04 AM is displayed as 11:04

2:00 PM is displayed as 2:00

Additional Note: I noticed that DateTimePicker is tracking the correct time. If I increase the time (I use ShowUpDown = true for this DateTimePicker control) and increase the time by 12 and save the changes to the database, AM / PM changes. Thus, it seems that β€œonly” is a problem for displaying the AM / PM part.

Thanks for any help. Franc

+4
source share
4 answers

try it

 dtpTime.Format = DateTimePickerFormat.Custom dtpTime.CustomFormat = "hh:mm tt" 
+7
source

I have the same problem. This is for "Why": In fact, according to MS: https://support2.microsoft.com/Default.aspx?scid=kb%3ben-us%3b889834&x=18&y=19 Date selection does not use the current stream culture: it uses regional user Settings. SO, if you force a custom date picker format containing "tt" and if the custom regional parameter has no pointer ... well, it will not be displayed.

+3
source

try the following:

 Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Label7.Text = DateTime.Now.ToString("MMM dd yyyy hh:mm:ss tt") End Sub 
+1
source

Make sure that in the Windows settings you have also correctly configured the time format for displaying AM / PM. The Windows time format must also be set to H: mm tt in order to correctly display the result.

0
source

Source: https://habr.com/ru/post/1436080/


All Articles