如何在 DateTimePicker 上显示小时和分钟
我正在使用 C# .NET,并且有一个带有 DateTimePicker 的 Windows 窗体。
我的问题是:如何显示小时和分钟(供用户更改)以及年、月和日?
I'm using C# .NET and I have a Windows Form with a DateTimePicker.
My question is: how can I display the hours and the minutes (for the user to change) along with the year, month, and day?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 CustomFormat 属性: http://msdn .microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat.aspx
它允许您设置您想要的格式。此外,要使其应用,您必须将 DatetimePicker.Format 设置为 Custom。
编辑:如果您提供您想要显示的格式的更好的想法/示例,我可以帮助您处理实际的格式字符串。
Check out the CustomFormat property: http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat.aspx
It allows you to set the format however you'd like. Also, to make it apply, you'll have to set the DatetimePicker.Format to Custom.
EDIT: If you provide a better idea/example of the format you want displayed, I can help with the actual format string.
将
Format
属性设置为DateTimePickerFormat.Custom
并设置CustomFormat
属性设置为包含时间的格式。Set the
Format
property toDateTimePickerFormat.Custom
and set theCustomFormat
property to a format that includes the time.请参阅此处了解所有 DateTimePicker 属性:
http://msdn .microsoft.com/en-us/library/system.windows.forms.datetimepicker_properties.aspx
Format 属性可让您设置包含小时、分钟、秒的格式字符串。
编辑:
以下是预定义的格式:
http://msdn .microsoft.com/en-us/library/system.windows.forms.datetimepickerformat.aspx
正如另一张海报提到的,您可以在 CustomFormat 属性中设置自己的格式。
See here for all DateTimePicker properties:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker_properties.aspx
The Format property will let you set a format string to include hours, minutes, seconds.
Edit:
Here are predefined formats:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepickerformat.aspx
As the other poster mentioned, you can set your own format in the CustomFormat property.