How to format day part of DateTime in one digit?
I have this: var date = new DateTime(2009, 12, 5);
...
... and need this: "Let's meet on December 5th."
If I do this: string.Format("Let's meet on {0:MMMM} {0:d}th", date)
...
... I get this: "Let's meet on December 12/05/2009th"
So how to output the day part (in one digit when lower than 10)?
(Please ignore the "1st"/"2nd"/"3rd"/"5th"开发者_运维问答 problem)
As per MSDN, try this:
string.Format("Let's meet on {0:MMMM} {0:%d}th", date)
or just make it one format specifier:
string.Format("Let's meet on {0:MMMM d}th", date)
string.Format("Let's meet on {0:MMMM} {1}th",date ,date.Day)
精彩评论