DateTime Format C# All Standard Formats

This is a reference article. The next table will contain all standard DateTime formats in the C# with examples:

Date FormatDescription
DateTime.Now.ToString(“MM/dd/yyyy”)05/29/2022
DateTime.Now.ToString(“dddd, dd MMMM yyyy”)Friday, 29 May 2022
DateTime.Now.ToString(“dddd, dd MMMM yyyy”)Friday, 29 May 2022 05:50
DateTime.Now.ToString(“dddd, dd MMMM yyyy”)Friday, 29 May 2022 05:50 AM
DateTime.Now.ToString(“dddd, dd MMMM yyyy”)Friday, 29 May 2022 5:50
DateTime.Now.ToString(“dddd, dd MMMM yyyy”)Friday, 29 May 2022 5:50 AM
DateTime.Now.ToString(“dddd, dd MMMM yyyy HH:mm:ss”)Friday, 29 May 2022 05:50:06
DateTime.Now.ToString(“MM/dd/yyyy HH:mm”)05/29/2022 05:50
DateTime.Now.ToString(“MM/dd/yyyy hh:mm tt”)05/29/2022 05:50 AM
DateTime.Now.ToString(“MM/dd/yyyy H:mm”)05/29/2022 5:50
DateTime.Now.ToString(“MM/dd/yyyy h:mm tt”)05/29/2022 5:50 AM
DateTime.Now.ToString(“MM/dd/yyyy HH:mm:ss”)05/29/2022 05:50:06
DateTime.Now.ToString(“MMMM dd”)May 29
DateTime.Now.ToString(“yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK”)2022-05-16T05:50:06.7199222-04:00
DateTime.Now.ToString(“ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’”)Fri, 16 May 2022 05:50:06 GMT
DateTime.Now.ToString(“yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss”)2022-05-16T05:50:06
DateTime.Now.ToString(“HH:mm”)05:50
DateTime.Now.ToString(“hh:mm tt”)05:50 AM
DateTime.Now.ToString(“H:mm”)5:50
DateTime.Now.ToString(“h:mm tt”)5:50 AM
DateTime.Now.ToString(“HH:mm:ss”)05:50:06
DateTime.Now.ToString(“yyyy MMMM”)2022 May

How to set Custom Format?

A number of string formats are used to format date and time output.

FormatDescription
dDay of the month. 1 to 31 (no leading zero)
ddDay of the month. 01 to 31 (with leading zero)
dddShort name of the day of the week
ddddFull name of the day of the week
MMonth. 1 to 12 (no leading zero)
MMMonth. 01 to 12 (with leading zero)
MMMBrief name of the month
MMMMFull month name
yOne or two last digits of the year (almost irrelevant)
yyThe last two digits of the year
yyyThe last three digits of the year
yyyyThe last four digits of the year
yyyyyThe last five digits of the year (will not be soon 🙂 )
hHour. 0 to 12. (no leading zero)
hhHour. 00 to 12 (with leading zero)
HHour. 0 to 23 (no leading zero)
HHHour. 00 to 23 (with leading zero)
mMinute. 0 to 59 (no leading zero)
mmMinute. 00 to 59 (with leading zero)
sSecond. 0 to 59 (no leading zero)
ssSecond. 00 to 59 (with leading zero)
from f to fffffffMilliseconds. The displayed number of digits corresponds to the number of “f”
KTimeZone
tHalf day. A or P
ttHalf day. AM or PM
zOffset in hours from GMT (no leading zero)
zzOffset in hours from GMT (with leading zero)
gPeriod or era
RGMT(Time by Greenwich)

Here is a code snippet with standard DateTime formats

DateTime today = DateTime.Now;
Console.WriteLine($"D: {today.ToString("D")}");
Console.WriteLine($"d: {today.ToString("d")}");
Console.WriteLine($"F: {today.ToString("F")}");
Console.WriteLine($"f: {today:f}");
Console.WriteLine($"G: {today:G}");
Console.WriteLine($"g: {today:g}");
Console.WriteLine($"M: {today:M}");
Console.WriteLine($"O: {today:O}");
Console.WriteLine($"o: {today:o}");
Console.WriteLine($"R: {today:R}");
Console.WriteLine($"s: {today:s}");
Console.WriteLine($"T: {today:T}");
Console.WriteLine($"t: {today:t}");
Console.WriteLine($"U: {today:U}");
Console.WriteLine($"u: {today:u}");
Console.WriteLine($"Y: {today:Y}");
Console.ReadLine();

 

Result:
C# DateTime Format

Leave a Comment