Contents
DateTimePicker.DisplayFormat Property |
|
Gets or sets a string value representing the display format of the DateTimePicker control.
The default value is "D" (LongDatePattern).
| Example Format | Control Display |
|---|---|
| D | (en-GB) |
| T | :: (en-GB) |
| hh:mm tt | : (en-GB) |
The following table lists the standard format characters for internationally accepted standard patterns. The format characters are case-sensitive; for example, 'g' and 'G' represent slightly different patterns. Note that on the whole the format handling of the DateTimePicker is almost identical to that of the associated Culture.DateTimeFormatInfo instance, the main exception being that day names "dddd" are not used anywhere.
| DisplayFormat Character | Associated Property/ Description | Example Format Pattern (en-US) |
|---|---|---|
| d | ShortDatePattern | MM/dd/yyyy |
| D | LongDatePattern | dd MMMM yyyy |
| f | Full date and time (long date and short time) | dd MMMM yyyy HH:mm |
| F | FullDateTimePattern (long date and long time) | dd MMMM yyyy HH:mm:ss |
| g | General (short date and short time) | MM/dd/yyyy HH:mm |
| G | General (short date and long time) | MM/dd/yyyy HH:mm:ss |
| m, M | MonthDayPattern | MMMM dd |
| r, R | RFC1123Pattern | dd MMM yyyy HH':'mm':'ss 'GMT' |
| s | SortableDateTimePattern (based on ISO 8601) using local time | yyyy'-'MM'-'dd'T'HH':'mm':'ss |
| t | ShortTimePattern | HH:mm |
| T | LongTimePattern | HH:mm:ss |
| u | UniversalSortableDateTimePattern using universal time | yyyy'-'MM'-'dd HH':'mm':'ss'Z' |
| U | Full date and time (long date and long time) using universal time | dd MMMM yyyy HH:mm:ss |
| y, Y | YearMonthPattern | yyyy MMMM |
The following table lists the patterns that can be combined to construct custom patterns. The patterns are case-sensitive; for example, "MM" is recognized, but "mm" is not. If the custom pattern contains white-space characters or characters enclosed in single quotation marks, the output string will also contain those characters. Characters not defined as part of a format pattern or as format characters are reproduced literally.
| Format Pattern | Description |
|---|---|
| d | The day of the month. Single-digit days will not have a leading zero. |
| dd | The day of the month. Single-digit days will have a leading zero. |
| M | The numeric month. Single-digit months will not have a leading zero. |
| MM | The numeric month. Single-digit months will have a leading zero. |
| MMM | The abbreviated 3 letter name of the month. |
| MMMM | The full name of the month. |
| yy | The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero. |
| yyyy | The year in four digits, including the century. |
| h | The hour in a 12-hour clock. Single-digit hours will not have a leading zero. |
| hh | The hour in a 12-hour clock. Single-digit hours will have a leading zero. |
| H | The hour in a 24-hour clock. Single-digit hours will not have a leading zero. |
| HH | The hour in a 24-hour clock. Single-digit hours will have a leading zero. |
| m | The minute. Single-digit minutes will not have a leading zero. |
| mm | The minute. Single-digit minutes will have a leading zero. |
| s | The second. Single-digit seconds will not have a leading zero. |
| ss | The second. Single-digit seconds will have a leading zero. |
| t | The first character in the AM/PM designator defined in Culture.DateTimeFormat.AMDesignator or Culture.DateTimeFormat.PMDesignator. |
| tt | The AM/PM designator defined in Culture.DateTimeFormat.AMDesignator or Culture.DateTimeFormat.PMDesignator. |
| : | The default time separator defined in Culture.DateTimeFormat.TimeSeparator. |
| / | The default date separator defined in Culture.DateTimeFormat.DateSeparator. |
| % c | character can be omitted if the format pattern is combined with literal characters or other format patterns. |
| \ c | Where c is any character. Displays the character literally. To display the backslash character, use "\\". |
Only format patterns listed in the second table above can be used to create custom patterns; standard format characters listed in the first table cannot be used to create custom patterns. Custom patterns must be least two characters long.
The main difference between the DateTimePicker's display format handling and that of the display format handling of datetimes in the .NET framework is that weekday names are not catered for, for obvious reasons.
You can insert html into your DisplayFormat. E.g. "yyyy<br>MMM<br>dd" would render the day beneath the month beneath the year.
An exception is thrown if not one of year, month, day, hour, minute or second is part of the Displayformat.
The control does not prevent the developer from entering nonsensical DisplayFormats. E.g. "yyyy/dd ss tt" will work but doesn't mean much. However, an h is converted to an H if t or tt is not present, and an H is converted to an h if t or tt is present.
[Visual Basic] Overridable Public Property DisplayFormat As System.String
[C#]
public virtual System.String DisplayFormat {get; set;}
[C++] public: __property virtual System.String get_DisplayFormat(); public: __property virtual void set_DisplayFormat(System.String);
[JScript] public function get DisplayFormat() : System.String; public function set DisplayFormat(System.String);
DateTimePicker Contents | DateTimePicker Overview | DateTimePicker Members
Support | Feedback | Contact Dune5 | Website
© 2001-2010 Dune5. All Rights Reserved.