DateTimePicker.CustomFormat 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定自訂的日期/時間格式字串。
public:
property System::String ^ CustomFormat { System::String ^ get(); void set(System::String ^ value); };
public string CustomFormat { get; set; }
public string? CustomFormat { get; set; }
member this.CustomFormat : string with get, set
Public Property CustomFormat As String
屬性值
一個代表自訂日期/時間格式的字串。 預設值為 null。
範例
以下程式碼範例將屬性設定 CustomFormat 為 DateTimePicker 「2001年6月1日 - 星期五」。 此程式碼假設在 上Form建立了控制實例DateTimePicker。
public:
void SetMyCustomFormat()
{
// Set the Format type and the CustomFormat string.
dateTimePicker1->Format = DateTimePickerFormat::Custom;
dateTimePicker1->CustomFormat = "MMMM dd, yyyy - dddd";
}
public void SetMyCustomFormat()
{
// Set the Format type and the CustomFormat string.
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}
Public Sub SetMyCustomFormat()
' Set the Format type and the CustomFormat string.
dateTimePicker1.Format = DateTimePickerFormat.Custom
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
End Sub
備註
若要顯示包含日期與時間分隔符的字串文字,或格式化字串,必須在子字串中使用跳脫字元。 例如,要將日期顯示為「6 月 15 日中午 12:00」,請將屬性設 CustomFormat 為「MMMM dd 'at' t:mm tt」。 若「at」子串未被轉義字元包圍,則為「June 15 aP 12:00PM」,因為「t」字元被讀作一個字母的 A.M./P.M. 格式字串(見下方格式字串表)。
格式字串可以組合起來,以格式化日期和時間。 例如,要將日期和時間顯示為 06/15/2001 中午 12:00,這個屬性應該設為「MM'/'dd'/'yyyy hh':'mm tt」。 欲了解更多資訊,請參閱 自訂日期與時間格式字串。
備註
Format必須將屬性設定為 ,DateTimePickerFormat.Custom才能影響顯示日期與時間的格式。
下表列出所有有效格式字串及其描述。
| 格式字串 | 說明 |
|---|---|
| d | 那是一兩位數的一天。 |
| dd | 兩位數的一天。 個位數的天數值前會加上 0。 |
| ddd | 三字元的星期幾縮寫。 |
| dddd | 完整的星期幾名稱。 |
| 小時 | 一小時或兩位數的節目,採用12小時格式。 |
| hh | 兩位數小時的節目,12小時格式。 單位數值前會加上 0。 |
| H | 24小時格式中的一或兩位數小時。 |
| HH | 24小時格式中的兩位數小時。 單位數值前會加上 0。 |
| m | 那一分鐘或兩位數的分鐘。 |
| 毫米 | 兩位數的分鐘。 單位數值前會加上 0。 |
| M | 那個一兩位數的月份號碼。 |
| 毫米 | 那兩位數的月份號碼。 單位數值前會加上 0。 |
| 嗯 | 三字元的月份縮寫。 |
| 嗯嗯 | 完整的月份名稱。 |
| s | 一兩位數的秒數。 |
| ss | 兩位數的秒數。 單位數值前會加上 0。 |
| t | A.M./P.M. 的縮寫(A.M. 顯示為「A」)。 |
| tt | A.M./P.M. 的兩個字母縮寫(A.M. 顯示為「AM」)。 |
| y | 一數字年份(2001年顯示為「1」)。 |
| yy | 年份的最後兩位數字(2001年顯示為「01」)。 |
| yyyy | 完整年份(2001年顯示為「2001」)。 |