DateTimePicker.CustomFormat プロパティ

定義

日付/時刻のカスタム書式指定文字列を取得または設定します。

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 設定して、日付を "2001 年 6 月 1 日 - 金曜日" として表示します DateTimePicker 。 このコードでは、 でコントロールの DateTimePicker インスタンスが作成 Formされていることを前提としています。

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" 部分文字列がエスケープ文字で囲まれていない場合、結果は "6 月 15 日 aP 12:00PM" になります。これは、"t" 文字が 1 文字の A.M./P.M. 書式指定文字列として読み取られます (下記の書式指定文字列表を参照)。

書式指定文字列を組み合わせて、日付と時刻の書式を設定できます。 たとえば、日付と時刻を 2001 年 6 月 15 日午後 12:00 として表示するには、このプロパティを "MM'/'dd'/'yyyy hh':'mm tt" に設定する必要があります。 詳細については、「 カスタム日付と時刻の書式指定文字列」を参照してください。

注意

表示される日付と時刻の Format 書式設定に DateTimePickerFormat.Custom 影響を与えるために、このプロパティの プロパティを に設定する必要があります。

次の表に、有効なすべての書式指定文字列とその説明を示します。

[書式設定文字列] [説明]
d 1 桁または 2 桁の日。
dd 2 桁の日。 1 桁の日の値の前に 0 が付く。
ddd 3 文字の曜日の省略形。
dddd 曜日の完全な名前。
h 12 時間形式の 1 桁または 2 桁の時間。
hh 12 時間形式の 2 桁の時間。 1 桁の値の前に 0 が付く。
H 24 時間形式の 1 桁または 2 桁の時間。
HH 24 時間形式の 2 桁の時間。 1 桁の値の前に 0 が付く。
m 1 桁または 2 桁の分。
mm 2 桁の分。 1 桁の値の前に 0 が付く。
M 1 桁または 2 桁の月番号。
mm 2 桁の月番号。 1 桁の値の前に 0 が付く。
MMM 3 文字の月の省略形。
MMMM 完全な月名。
s 1 桁または 2 桁の秒。
ss 2 桁の秒。 1 桁の値の前に 0 が付く。
t 1 文字の A.M./P.M. 省略形 (A.M. は "A" として表示されます)。
tt 2 文字の A.M./P.M. 省略形 (A.M. は "AM" として表示されます)。
1 桁の年 (2001 年は "1" と表示されます)。
yy 年の最後の 2 桁 (2001 年は "01" と表示されます)。
yyyy 通年 (2001 年は "2001" と表示されます)。

適用対象

こちらもご覧ください