C# Language Date Formatting


Example

DateTime date = new DateTime(2016, 07, 06, 18, 30, 14);
// Format: year, month, day hours, minutes, seconds

Console.Write(String.Format("{0:dd}",date)); 

//Format by Culture info
String.Format(new System.Globalization.CultureInfo("mn-MN"),"{0:dddd}",date);
6.0
Console.Write($"{date:ddd}");

output :

06
Лхагва
06
SpecifierMeaningSampleResult
dDate{0:d}7/6/2016
ddDay, zero-padded{0:dd}06
dddShort day name{0:ddd}Wed
ddddFull day name{0:dddd}Wednesday
DLong date{0:D}Wednesday, July 6, 2016
fFull date and time, short{0:f}Wednesday, July 6, 2016 6:30 PM
ffSecond fractions, 2 digits{0:ff}20
fffSecond fractions, 3 digits{0:fff}201
ffffSecond fractions, 4 digits{0:ffff}2016
FFull date and time, long{0:F}Wednesday, July 6, 2016 6:30:14 PM
gDefault date and time{0:g}7/6/2016 6:30 PM
ggEra{0:gg}A.D
hhHour (2 digits, 12H){0:hh}06
HHHour (2 digits, 24H){0:HH}18
MMonth and day{0:M}July 6
mmMinutes, zero-padded{0:mm}30
MMMonth, zero-padded{0:MM}07
MMM3-letter month name{0:MMM}Jul
MMMMFull month name{0:MMMM}July
ssSeconds{0:ss}14
rRFC1123 date{0:r}Wed, 06 Jul 2016 18:30:14 GMT
sSortable date string{0:s}2016-07-06T18:30:14
tShort time{0:t}6:30 PM
TLong time{0:T}6:30:14 PM
ttAM/PM{0:tt}PM
uUniversal sortable local time{0:u}2016-07-06 18:30:14Z
UUniversal GMT{0:U}Wednesday, July 6, 2016 9:30:14 AM
YMonth and year{0:Y}July 2016
yy2 digit year{0:yy}16
yyyy4 digit year{0:yyyy}2016
zz2 digit timezone offset{0:zz}+09
zzzfull time zone offset{0:zzz}+09:00