DateTimePicker控件不显示AM / PM [英] DateTimePicker control does not show AM/PM

查看:430
本文介绍了DateTimePicker控件不显示AM / PM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用自定义格式的DateTimePicker控件出现问题,该格式包含两个字母的A.M./P.M。

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

使用 zh-CN CultureInfo DateTimeFormat.ShortTimePattern会生成
h:mm tt。

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

但是使用以下代码在DateTimePicker中将其设置为自定义格式:

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

仅显示小时和分钟。
但是我也需要AM / PM部分。

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

示例:

11:04 AM显示为11:04

11:04 AM is displayed as 11:04

2:00 PM显示为2:00

2:00 PM is displayed as 2:00

附加说明:
我注意到DateTimePicker跟踪正确的时间。
如果我增加了时间(此DateTimePicker控件使用ShowUpDown = true),并且将小时数增加了12小时并将更改保存到数据库中,则AM / PM已更改。
因此,显示AM / PM部分似乎只是一个问题。

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.

感谢您的帮助。
Frank

Thanks for any help. Frank

推荐答案

尝试一下

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

这篇关于DateTimePicker控件不显示AM / PM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆