Custom Date/Time Format Strings

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

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 (e.g.: '%d').

CharacterDescription
dDisplays 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.
ddDisplays 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).
dddDisplays the abbreviated name of the day for the specified Date/Time.
ddddDisplays the full name of the day for the specified Date/Time.
fDisplays the most significant digit of the seconds fraction.
ffDisplays the two most significant digits of the seconds fraction.
f fDisplays the x most significant digits of the seconds fraction where x is the number of f characters.
FDisplays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero.
FFDisplays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.
F FDisplays the x most significant digits of the seconds fraction. However, trailing zeros, or x zero digits, are not displayed where x is the number of F characters.
gDisplays the era (A.D. for example) for the specified Date/Time.
hDisplays the hour for the specified Date Time 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.
hhDisplays the hour for the specified Date Time 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).
HDisplays the hour for the specified Date Time 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.
HHDisplays the hour for the specified Date Time 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).
mDisplays the minute for the specified Date Time 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.
mmDisplays the minute for the specified Date Time 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).
MDisplays 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.
MMDisplays 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).
MMMDisplays the abbreviated name of the month for the specified Date/Time.
MMMMDisplays the full name of the month for the specified Date/Time.
oDisplays the current day of the year, measured as a number between 1 and 365 (366 for leap years), inclusive. If the day is a single digit only (1-9), then it is displayed as a single digit.
ooDisplays the current day of the year, measured as a number between 1 and 365 (366 for leap years), inclusive. If the day is a single digit only (1-9), it is formatted with a preceding 0 (01-09).
oooDisplays the current day of the year, measured as a number between 1 and 365 (366 for leap years), inclusive. If the day is 1 or 2 digits only (1-99), it is formatted with 1 or 2 preceding 0's (001-099).
sDisplays the seconds for the specified Date Time 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.
ssDisplays the seconds for the specified Date Time 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).
tDisplays the first character of the A.M./P.M. designator for the specified Date/Time
ttDisplays the A.M./P.M. designator for the specified Date/Time.
yDisplays the year for the specified Date/Time 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.
yyDisplays the year for the specified Date/Time 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).
yyyyDisplays the year for the specified Date/Time, 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.
zDisplays the time zone offset for the system's current time zone in whole hours only. If the offset is a single digit (0-9), it is displayed as a single digit with the appropriate leading sign.
zzDisplays the time zone offset for the system's current time zone in whole hours only. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign.
zzzDisplays the time zone offset for the system's current time zone in hours and minutes. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign.
:Time Separator
/Date Separator

Date / Time Format Samples:

Note: All samples assume en-US culture is in use.

FormatOutput
d4/10/2001
DTuesday, April 10, 2001
t3:51 PM
T3:51:24 PM
fTuesday, April 10, 2001 3:51 PM
FTuesday, April 10, 2001 3:51:24 PM
g4/10/2001 3:51 PM
G4/10/2001 3:51:24 PM
s2001-04-10T15:51:24
mApril 10
yApril, 2001
d, M10, 4
d MMMM10 April
ddd MMM yyThur Apr 01
ddd MMMM yyyyThur April 2001
dddd MMMM yy ggThursday April 01 A.D.
h:m:s3:51:24
hh:mm:ss03:51:24
HH-mm-ss-t15-51-24-P
HH-mm-ss-tt15-51-24-PM