Convert date time format from dd/MM/yyyy to MM/dd/yyyy [duplicate]
Possible Duplicate:
Convert dd-mm-yyyy into mm/dd/yyyyy in C#
I want to Convert Date time format from dd/MM/yyyy
to MM/dd/yyyy
i开发者_如何学Pythonn C#
Is there any suggestion how to do that?
Please try:
string oldstr = "03/12/2011";
string strDate = DateTime.ParseExact(oldstr, "dd/MM/yyyy",null).ToString("MM/dd/yyyy");
Console.WriteLine(strDate);
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat; //--MM/dd/yyyy
DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat; //--dd/MM/yyyy
DateTime result = Convert.ToDateTime("07/21/2011", usDtfi); //or: ("21/07/2011", ukDtfi)
Then you have a DateTime Object (result) and do whatever you want like:
string str = result.ToString("yyyy-MM-dd HH:mm:ss");
Happy Coding :)
try this
string DateString = "22/04/2011";
DateTime date = new DateTime();
date = DateTime.ParseExact(DateString, "dd/MM/yyyy");
string NewDateString = date.ToString("MM/dd/yyyy");
精彩评论