Gets or sets the custom date/time format string.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Property CustomFormat As String
Dim instance As DateTimePicker
Dim value As String
value = instance.CustomFormat
instance.CustomFormat = value
public string CustomFormat { get; set; }
public:
property String^ CustomFormat {
String^ get ();
void set (String^ value);
}
public function get CustomFormat () : String
public function set CustomFormat (value : String)
Property Value
Type:
System..::.StringA string that represents the custom date/time format. The default is nullNothingnullptra null reference (Nothing in Visual Basic).
To display string literals that contain date and time separators or to format strings, you must use escape characters in the substring. For example, to display the date as "June 15 at 12:00 PM", set the CustomFormat property to "MMMM dd 'at' t:mm tt". If the "at" substring is not enclosed by escape characters, the result is "June 15 aP 12:00PM" because the "t" character is read as the one-letter A.M./P.M. format string (see the format string table below).
The format strings can be combined to format the date and time. For example, to display the date and time as 06/15/2001 12:00 PM, this property should be set to "MM'/'dd'/'yyyy hh':'mm tt". For more information, see Date and Time Format Strings.
The following table lists all the valid format strings and their descriptions.
Format string | Description |
|---|
d | The one- or two-digit day. |
dd | The two-digit day. Single-digit day values are preceded by a 0. |
ddd | The three-character day-of-week abbreviation. |
dddd | The full day-of-week name. |
h | The one- or two-digit hour in 12-hour format. |
hh | The two-digit hour in 12-hour format. Single digit values are preceded by a 0. |
H | The one- or two-digit hour in 24-hour format. |
HH | The two-digit hour in 24-hour format. Single digit values are preceded by a 0. |
m | The one- or two-digit minute. |
mm | The two-digit minute. Single digit values are preceded by a 0. |
M | The one- or two-digit month number. |
MM | The two-digit month number. Single digit values are preceded by a 0. |
MMM | The three-character month abbreviation. |
MMMM | The full month name. |
s | The one- or two-digit seconds. |
ss | The two-digit seconds. Single digit values are preceded by a 0. |
t | The one-letter A.M./P.M. abbreviation (A.M. is displayed as "A"). |
tt | The two-letter A.M./P.M. abbreviation (A.M. is displayed as "AM"). |
y | The one-digit year (2001 is displayed as "1"). |
yy | The last two digits of the year (2001 is displayed as "01"). |
yyyy | The full year (2001 is displayed as "2001"). |
The following code example sets the CustomFormat property so that the DateTimePicker will display the date as "June 01, 2001 - Friday". This code assumes that an instance of a DateTimePicker control has been created on a 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
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";
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0
Reference