HomeGuidesRecipesAPI
HomeGuidesAPILog In

Custom date/time format strings

This page is a summary of the information from the Custom date and time format strings from Microsoft.

For detailed information and examples on the use of these formats please see the Microsoft page.

FormatDescription
[:]Time separator. In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system's LocaleID value.
[/]Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your locale.
[%]Used to indicate that the following character should be read as a single-letter format without regard to any trailing letters. Also used to indicate that a single-letter format is read as a user-defined format. See below for further details.
dDisplays the day as a number without a leading zero (for example, 1). Use %d if this is the only character in your user-defined numeric format.
ddDisplays the day as a number with a leading zero (for example, 01).
dddDisplays the day as an abbreviation (for example, Sun).
ddddDisplays the day as a full name (for example, Sunday).
MDisplays the month as a number without a leading zero (for example, January is represented as 1). Use %M if this is the only character in your user-defined numeric format.
MMDisplays the month as a number with a leading zero (for example, 01/12/01).
MMMDisplays the month as an abbreviation (for example, Jan).
MMMMDisplays the month as a full month name (for example, January).
ggDisplays the period/era string (for example, A.D.)
hDisplays the hour as a number without leading zeros using the 12-hour clock (for example, 1:15:15 PM). Use %h if this is the only character in your user-defined numeric format.
hhDisplays the hour as a number with leading zeros using the 12-hour clock (for example, 01:15:15 PM).
HDisplays the hour as a number without leading zeros using the 24-hour clock (for example, 1:15:15). Use %H if this is the only character in your user-defined numeric format.
HHDisplays the hour as a number with leading zeros using the 24-hour clock (for example, 01:15:15).
mDisplays the minute as a number without leading zeros (for example, 12:1:15). Use %m if this is the only character in your user-defined numeric format.
mmDisplays the minute as a number with leading zeros (for example, 12:01:15).
sDisplays the second as a number without leading zeros (for example, 12:15:5). Use %s if this is the only character in your user-defined numeric format.
ssDisplays the second as a number with leading zeros (for example, 12:15:05).
FDisplays fractions of seconds. For example ff will display hundredths of seconds, whereas ffff will display ten-thousandths of seconds. You may use up to seven f symbols in your user-defined format. Use %f if this is the only character in your user-defined numeric format.
TUses the 12-hour clock and displays an uppercase A for any hour before noon; displays an uppercase P for any hour between noon and 11:59 P.M. Use %t if this is the only character in your user-defined numeric format.
ttUses the 12-hour clock and displays an uppercase AM with any hour before noon; displays an uppercase PM with any hour between noon and 11:59 P.M.
yDisplays the year number (0-9) without leading zeros. Use %y if this is the only character in your user-defined numeric format.
yyDisplays the year in two-digit numeric format with a leading zero, if applicable.
yyyDisplays the year in four digit numeric format.
yyyyDisplays the year in four digit numeric format.
zDisplays the timezone offset without a leading zero (for example, -8). Use %z if this is the only character in your user-defined numeric format.
zzDisplays the timezone offset with a leading zero (for example, -08)
zzzDisplays the full timezone offset (for example, -08:00)