开发者

how to conver date string from one format to another format in c#?

Suppose I have date string like mydate = "24-Jun-2011";

I want to convert it to another format "2011开发者_JAVA百科-06-24". What is the simple way to do this?


The best way is to parse the string to a DateTime and then convert it to a string again.

Be sure to have a look at the documentation for DateTime.Parse, DateTime.TryParse and DateTime.ToString

DateTime.Parse(myDate).ToString("yyyy-MM-dd");


DateTime.ParseExact("24-Jun-2011", "dd-MMM-yyyy").ToString ("yyyy-MM-dd")

See formats here at MSDN.


U can Parse it to DateTime and then using tostring + special format get what u need


http://www.csharp-examples.net/string-format-datetime/ has a lot of different formatting options... This should work well for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜