我已經搜索過,但無法得到答案。我在WinForms對話框中使用DateTimePicker並指定一個自定義格式:dd.MM.yyyy HH:mm:ss
。但是DateTimePicker不顯示秒數,它總是爲他們顯示00
。即使我輸入例如「15」秒,該值是正確的,但顯示錯誤。DateTimePicker和秒
我做錯了什麼?
我已經搜索過,但無法得到答案。我在WinForms對話框中使用DateTimePicker並指定一個自定義格式:dd.MM.yyyy HH:mm:ss
。但是DateTimePicker不顯示秒數,它總是爲他們顯示00
。即使我輸入例如「15」秒,該值是正確的,但顯示錯誤。DateTimePicker和秒
我做錯了什麼?
我發現了我自己的答案。如果我將數據源綁定到DateTimePicker的Text屬性,則不會顯示秒數。我必須改爲綁定到Value屬性。
您是否在指定自定義格式之前設置了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
我在設計器的屬性表中指定了這些值。 – Fischermaen
您是否將'Format'設置爲'custom'?因爲我試過了,它顯示了當前時間秒 – Nasreddine
@Nacereddine:是的,我做了,我可以按照我期望的方式看到格式化的日期。 – Fischermaen
[也適用於我](http://i.imgur.com/nmi5B.png)。你必須有其他事情出錯了。 – Otiel