DateTimePicker and seconds

孤者浪人 提交于 2019-12-20 06:33:27

问题


I've searched SO, but could't get the answer. I use a DateTimePicker on a WinForms dialog and specify a custom format: dd.MM.yyyy HH:mm:ss. But DateTimePicker doesn't show the seconds, it always shows 00 for them. Even if I type e.g. "15" seconds, the value is correct but it's shown wrong.

What did I do wrong?


回答1:


I've found out the answer by myself. If I bind the data source to the Text property of DateTimePicker, the seconds will not be shown. I have to bind to the Value property instead.




回答2:


Did you set the Format property before specifying your custom format?

public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}

Example cadged from the MSDN page for DateTimePicker.CustomFormat Property



来源:https://stackoverflow.com/questions/8359380/datetimepicker-and-seconds

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