开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜