0

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?

Fischermaen
  • 12,238
  • 2
  • 39
  • 56
  • 1
    Did you set the `Format` to `custom` ? because I tried it and it shows the current time seconds – Nasreddine Dec 02 '11 at 16:30
  • @Nacereddine: Yes, I did and I can see the date formated in the way I expect it. – Fischermaen Dec 02 '11 at 16:30
  • [Works for me too](http://i.imgur.com/nmi5B.png). You must have something else going wrong. – Otiel Dec 02 '11 at 16:34
  • @Fischermaen It's [working fine](http://i.imgur.com/GndoN.png) for me at design time and runtime. Do you have some other parts of your code that modify that DateTimePicker ? Did you try it at runtime ? – Nasreddine Dec 02 '11 at 16:45
  • 1
    DTP is implemented by Windows, not .NET. DateTimePicker is just a wrapper class for it. Unanswerable without knowing what Windows version you use. You'd better also look at Control Panel + Regional and Language options for user overrides. – Hans Passant Dec 02 '11 at 16:50
  • Test is running under Windows 7 SP 1. All language settings are for Germany. But I don't think that not displaying the seconds has anything to do with the language settings. – Fischermaen Dec 02 '11 at 21:47

2 Answers2

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.

Fischermaen
  • 12,238
  • 2
  • 39
  • 56
0

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

Talvalin
  • 7,789
  • 2
  • 30
  • 40