次の方法で共有


DateTimePicker.CustomFormat プロパティ

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

Public Property CustomFormat As String
[C#]
public string CustomFormat {get; set;}
[C++]
public: __property String* get_CustomFormat();public: __property void set_CustomFormat(String*);
[JScript]
public function get CustomFormat() : String;public function set CustomFormat(String);

プロパティ値

カスタムの日付/時刻書式を表す文字列。既定値は null 参照 (Visual Basic では Nothing) です。

解説

日付と時刻の区切り記号や書式指定文字列を含むリテラル文字列を表示するには、部分文字列に対してエスケープ文字を使用する必要があります。たとえば、日付を "June 06 at 3:00 PM" と表示するには、 CustomFormat プロパティを "MMMM dd 'at' t:mm tt" に設定します。部分文字列 "at" をエスケープ文字で囲まなかった場合は、"June 06 aP 3:00PM" と表示されます。これは、文字 "t" が 1 文字の AM/PM の書式指定文字列として解釈されたためです (次の書式指定文字列の表を参照)。

書式指定文字列を組み合わせて、日付と時刻の書式を指定できます。たとえば、日付と時刻を 06/01/2001 12:00 PM と表示するには、このプロパティを "dd'/'MM'/'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 文字の AM/PM の省略形 ("AM" の場合は "A")。
tt 2 文字の AM/PM の省略形 ("AM" の場合は "AM")。
y 1 桁の年 (2001 年の場合は "1")。
yy 年の最後の 2 桁 (2001 の場合は "01")。
yyyy 完全な年 (2001 の場合は "2001")。

使用例

[Visual Basic, C#, C++] DateTimePicker で日付が "June 01, 2001 - Friday" と表示されるように、 CustomFormat プロパティを設定する例を次に示します。このコードは、 DateTimePicker コントロールのインスタンスが Form 上に作成されていることを前提にしています。

 
Public Sub SetMyCustomFormat()
    ' Set the Format type and the CustomFormat string.
    dateTimePicker1.Format = DateTimePickerFormat.Custom
    dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
End Sub 'SetMyCustomFormat

[C#] 
public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}


[C++] 
public:
void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1->Format = DateTimePickerFormat::Custom;
   dateTimePicker1->CustomFormat = S"MMMM dd, yyyy - dddd";
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DateTimePicker クラス | DateTimePicker メンバ | System.Windows.Forms 名前空間 | DateTimePickerFormat | Format