开发者

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

开发者 https://www.devze.com 2023-03-13 12:58 出处:网络
Suppose I have date string like mydate = \"24-Jun-2011\"; I want to convert it to another format \"2011开发者_JAVA百科-06-24\".

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

精彩评论

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