DateTimePicker and seconds

2019-03-04 01:53发布

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?

2条回答
贪生不怕死
2楼-- · 2019-03-04 02:14

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.

查看更多
混吃等死
3楼-- · 2019-03-04 02:31

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 - ffffdd";
}

Example cadged from the MSDN page for DateTimePicker.CustomFormat Property

查看更多
登录 后发表回答