.NET Date and Time Format Masks
Standard masks which vary based on the culture being used. For example, using the short time character t, the time 2:30:22 am would display for US English as: 2:30
Character | Description | Example (US English) |
d | Short date | 1/1/2001 |
D | Long date | Monday, January 1, 2001 |
f | Full date and time (long date and short time) | Monday, January 1, 2001 10:30 a |
F | Full date and time (long date and long time) | Monday, January 1, 2001 10:30:22 am |
g | General date (short date and short time) | 1/1/2001 10:30a |
G | General date (short date and long time) | 1/1/2001 10:30:22 a |
m,M | Month and day | January, 1 |
r,R | RFC 1123 specification | Mon, 1 JAN 2001 10:30:22 GMT |
t | Short time | 10:30 a |
T | Long time | 10:30:22 am |
y,Y | Year month | January 2001 |
Individual components used to build custom format masks that are independent of culture.
Pattern | Description | Example (US English) |
d | The day of the month. Single-digit days will not have a leading zero | 1 |
dd | The day of the month. Single-digit days will have a leading zero | 01 |
ddd | The abbreviated name of the day of the week | MON |
dddd | The full name of the day of the week | Monday |
M | The numeric month. Single-digit months will not have a leading zero | 1 |
MM | The numeric month. Single-digit months will have a leading zero | 01 |
MMM | The abbreviated name of the month | JAN |
MMMM | The full name of the month | January |
y | The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero | 1 |
yy | The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero | 01 |
yyyy | The year in four digits, including the century | 2001 |
h | The hour in a 12-hour clock. Single-digit hours will not have a leading zero | 1 |
hh | The hour in a 12-hour clock. Single-digit hours will have a leading zero | 01 |
H | The hour in a 24-hour clock. Single-digit hours will not have a leading zero | 1 |
HH | The hour in a 24-hour clock. Single-digit hours will have a leading zero | 01 |
m | The minute. Single-digit minutes will not have a leading zero | 1 |
mm | The minute. Single-digit minutes will have a leading zero | 01 |
s | The second. Single-digit seconds will not have a leading zero | 1 |
ss | The second. Single-digit seconds will have a leading zero | 01 |
f | The fraction of a second in single-digit precision. The remaining digits are truncated | 1 |
ff | The fraction of a second in double-digit precision. The remaining digits are truncated | 11 |
fff | The fraction of a second in three-digit precision. The remaining digits are truncated | 111 |
ffff | The fraction of a second in four-digit precision. The remaining digits are truncated | 1111 |
fffff | The fraction of a second in five-digit precision. The remaining digits are truncated | 11111 |
ffffff | The fraction of a second in six-digit precision. The remaining digits are truncated | 111111 |
fffffff | The fraction of a second in seven-digit precision. The remaining digits are truncated | 1111111 |
t | The first character in the AM/PM designator | p |
tt | The AM/PM designator | pm |
z | The GMT time zone offset ("+" or "-" followed by the hour only). Single-digit hours will not have a leading zero | Pacific Standard Time is "-8" |
zz | The GMT time zone offset ("+" or "-" followed by the hour only). Single-digit hours will have a leading zero | Pacific Standard Time is "-08" |
zzz | The full GMT time zone offset ("+" or "-" followed by the hour and minutes). Singledigit hours and minutes will have leading zeros | Pacific Standard Time is "-08:00" |
: | The default time separator defined for the culture | : |
/ | The default date separator defined for the culture | / |
\c | Where c is any character. Displays the character literally. To display the backslash character, use "\\" |
\\ |