开发者

How to format day part of DateTime in one digit?

开发者 https://www.devze.com 2022-12-09 17:29 出处:网络
I have this: var date = new DateTime(2009, 12, 5);... ... and need this: \"Let\'s meet on December 5th.\"

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

精彩评论

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