DateTime Picker In WinForm How To Pick Time? [duplicate]

巧了我就是萌 提交于 2019-11-30 17:06:08

You can use the built in DateTime picker by adding a custom format string as follows:

DateTimePicker.ShowUpDown = true;
DateTimePicker.CustomFormat = "hh:mm";
DateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

Enjoy!

F.P

You can either choose the datepicker to have a "long" date, even only "time" or you can create your custom date.

I always use this format, as it's the most easy one to understand for users (IMHO): yyyy.MM.dd HH:mm

This can be done in the designer the fastest, just change the property.

Or, change it in the program with

YourDatePicker.Format = DateTimePickerFormat.Custom;
YourDatePicker.CustomFormat = "yyyy.MM.dd HH:mm";

The DateTimePicker works pretty much like how setting the Windows clock works. If you set the ShowUpDown property to true, it displays a spin control to the right of the DateTimePicker. If you then click on a section of the control, such as the time in hours, and then hit the up or down arrow of the spin control, it will change the time in hours.

Also, if you want to use a custom DateTime format, change the Format property to Custom and set the flags you'd like. For example, MM dddd yyyy HH:mm:ss. For an explanation of all the custom format specifiers, here's the full list of them from MSDN.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!