format date in c#

2019-01-02 16:20发布

How can I format a date as dd/mm/yyyy or mm/dd/yy ?

Like in VB format("dd/mm/yy",now)

How can I do this in C#?

7条回答
千与千寻千般痛.
2楼-- · 2019-01-02 16:48

In you can also write

DateTime aDate = new DateTime(); 
string s = aDate.ToShortDateString();

for a short notation

or

DateTime aDate = new DateTime(); 
string s = aDate.ToLongDateString();

for a long notation like "Sunday, Febuary 1, 2009".

Or take a look at MSDN for the possibities of .ToString("???");

查看更多
登录 后发表回答