DateTimePicker custom formats
Previous  Next

You can exercise greater control over how a DateTimePicker object is formatted by using custom DateTime format specifiers to create your own custom DateTime format string. Combine one or more custom format specifiers to construct a DateTime formatting pattern that yields the output you prefer.

The following table describes the custom format specifiers and the results they produce. The output of these format specifiers is influenced by the current culture and the settings in the Regional Options control panel.


d
 Displays the current day of the month, measured as a number between 1 and 31, inclusive. If the day is a single digit only (1-9), then it is displayed as a single digit.
 
dd
 Displays the current day of the month, measured as a number between 1 and 31, inclusive. If the day is a single digit only (1-9), it is formatted with a preceding 0 (01-09).
 
ddd
 Displays the abbreviated name of the day for the specified DateTime.
 
dddd (plus any number of additional "d" characters)
 Displays the full name of the day for the specified DateTime.
 
f
 Displays the most significant digit of the seconds fraction.
 
ff
 Displays the two most significant digits of the seconds fraction.
 
fff
 Displays the three most significant digits of the seconds fraction.
 
ffff
 Displays the four most significant digits of the seconds fraction.
 
fffff
 Displays the five most significant digits of the seconds fraction.
 
ffffff
 Displays the six most significant digits of the seconds fraction.
 
fffffff
 Displays the seven most significant digits of the seconds fraction.
 
F
 Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero.

FF
 Displays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.
 
FFF
 Displays the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.
 
FFFF
 Displays the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.
 
FFFFF
 Displays the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.
 
FFFFFF
 Displays the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.
 
FFFFFFF
 Displays the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.
 
g or gg (plus any number of additional "g" characters)
 Displays the era (A.D. for example).
 
h
 Displays the hour in the range 1-12. The hour represents whole hours passed since either midnight (displayed as 12) or noon (also displayed as 12). If this format is used alone, then the same hour before or after noon is indistinguishable. If the hour is a single digit (1-9), it is displayed as a single digit. No rounding occurs when displaying the hour. For example, a DateTime of 5:43 returns 5.
 
hh(plus any number of additional "h" characters)
 Displays the hour in the range 1-12. The hour represents whole hours passed since either midnight (displayed as 12) or noon (also displayed as 12). If this format is used alone, then the same hour before or after noon is indistinguishable. If the hour is a single digit (1-9), it is formatted with a preceding 0 (01-09).
 
H
 Displays the hour in the range 0-23. The hour represents whole hours passed since midnight (displayed as 0). If the hour is a single digit (0-9), it is displayed as a single digit.
 
HH (plus any number of additional "H" characters)
 Displays the hour in the range 0-23. The hour represents whole hours passed since midnight (displayed as 0). If the hour is a single digit (0-9), it is formatted with a preceding 0 (01-09).
 
m
 Displays the minute in the range 0-59. The minute represents whole minutes passed since the last hour. If the minute is a single digit (0-9), it is displayed as a single digit.

mm(plus any number of additional "m" characters)
 Displays the minute in the range 0-59. The minute represents whole minutes passed since the last hour. If the minute is a single digit (0-9), it is formatted with a preceding 0 (01-09).
 
M
 Displays the month, measured as a number between 1 and 12, inclusive. If the month is a single digit (1-9), it is displayed as a single digit.
 
MM
 Displays the month, measured as a number between 1 and 12, inclusive. If the month is a single digit (1-9), it is formatted with a preceding 0 (01-09).
 
MMM
 Displays the abbreviated name of the month.
 
MMMM
 Displays the full name of the month.
 
s
 Displays the seconds in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is displayed as a single digit only.
 
ss(plus any number of additional "s" characters)
 Displays the seconds in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is formatted with a preceding 0 (01-09).
 
t
 Displays the first character of the A.M./P.M. designator.
 
tt (plus any number of additional "t" characters)
 Displays the A.M./P.M. designator.
 
y
 Displays the year as a maximum two-digit number. The first two digits of the year are omitted. If the year is a single digit (1-9), it is displayed as a single digit.
 
yy
 Displays the year as a maximum two-digit number. The first two digits of the year are omitted. If the year is a single digit (1-9), it is formatted with a preceding 0 (01-09).
 
yyyy
 Displays the year, including the century. If the year is less than four digits in length, then preceding zeros are appended as necessary to make the displayed year four digits long.
 
z
 Displays the time zone offset for the system's current time zone in whole hours only. The offset is always displayed with a leading sign (zero is displayed as "+0"), indicating hours ahead of Greenwich mean time (+) or hours behind Greenwich mean time (-). The range of values is –12 to +13. If the offset is a single digit (0-9), it is displayed as a single digit with the appropriate leading sign. The setting for the time zone is specified as +X or –X where X is the offset in hours from GMT. The displayed offset is affected by daylight savings time.
 
zz
 Displays the time zone offset for the system's current time zone in whole hours only. The offset is always displayed with a leading or trailing sign (zero is displayed as "+00"), indicating hours ahead of Greenwich mean time (+) or hours behind Greenwich mean time (-). The range of values is –12 to +13. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign. The setting for the time zone is specified as +X or –X where X is the offset in hours from GMT. The displayed offset is affected by daylight savings time.
 
zzz (plus any number of additional "z" characters)
 Displays the time zone offset for the system's current time zone in hours and minutes. The offset is always displayed with a leading or trailing sign (zero is displayed as "+00:00"), indicating hours ahead of Greenwich mean time (+) or hours behind Greenwich mean time (-). The range of values is –12:00 to +13:00. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign. The setting for the time zone is specified as +X or –X where X is the offset in hours from GMT. The displayed offset is affected by daylight savings time.
 
:
 Time separator.
 
/
 Date separator.
 
"
 Quoted string. Displays the literal value of any string between two quotation marks preceded by the escape character (/).
 
'
 Quoted string. Displays the literal value of any string between two " ' " characters.
 
%c
 Where c is both a standard format specifier and a custom format specifier, displays the custom format pattern associated with the format specifier.

Note that if a format specifier is used alone as a single character, it is interpreted as a standard format specifier. Only format specifiers consisting of two or more characters are interpreted as custom format specifiers. In order to display the custom format for a specifier defined as both a standard and a custom format specifier, precede the specifier with a % symbol.
 
\c
 Where c is any character, the escape character displays the next character as a literal. The escape character cannot be used to create an escape sequence (like "\n" for new line) in this context.
 
Any other character
 Other characters are written directly to the result string as literals.