How to format the day part of DateTime in one digit?

I have this: var date = new DateTime(2009, 12, 5);...

... and you need the following: "Let meet on December 5th."

If I do this: string.Format("Let meet on {0:MMMM} {0:d}th", date)...

... I get this: "Let meet on December 12/05/2009th"

So, how to deduce part of the day (in one digit, when below 10)?

(Please ignore the problem "1st" / "2nd" / "3rd" / "5th")

+3
source share
2 answers

As in MSDN , try the following:

string.Format("Let meet on {0:MMMM} {0:%d}th", date)

or just create it in one format specifier:

string.Format("Let meet on {0:MMMM d}th", date)
+5
source
string.Format("Let meet on {0:MMMM} {1}th",date ,date.Day)
-1
source

Source: https://habr.com/ru/post/1720763/


All Articles