开发者

How to format 2010-11-24 date in C#?

开发者 https://www.devze.com 2023-01-26 11:46 出处:网络
I am using ((DateTime)newsItem.Date).ToString(@\"yyyy MM dd\") which giv开发者_JAVA技巧es me 2010 11 24 but not 2010-11-24.

I am using

((DateTime)newsItem.Date).ToString(@"yyyy MM dd") 

which giv开发者_JAVA技巧es me 2010 11 24 but not 2010-11-24.

I want dashes in between the numbers of date.


Have you tried

((DateTime)newsItem.Date).ToString(@"yyyy-MM-dd");

Also, since you format the time part away anyway in the ToString, you don't need to add .Date, and you can change it to

((DateTime)newsItem).ToString(@"yyyy-MM-dd");


https://web.archive.org/web/20211020131217/https://www.4guysfromrolla.com/articles/111010-1.aspx This will help you.

0

精彩评论

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