YoTo Blog

C# Date Format


Date Format Notation

  • Date: 2024-01-01 09:01:01 PM 123
  • Case sensitive.
CodeDescriptionExample
yyyy4 digits for year2024
yyLast 2 digits for year24
yLast 1 digit for year4
MM2 digits for month with 001
M1~2 digits for month1
dd2 digits for day with 001
d1~2 digits for day1
hh2 digits for 12-hour format09
h1~2 digits for 12-hour format9
HH2 digits for 24-hour format21
H1~2 digits for 24-hour format21
mm2 digits for minute01
m1~2 digits for minute1
ss2 digits for second01
s1~2 digits for second1
fffmillisecond123
tt2 digits for AM, PMPM
t1 digit for AM, PMP

Conclusion

I've organized the C# date format.
More formats
There are more formats if you access the MS site.