I need to convert an string date with format yyyyMMdd
to a date string with format MM/dd/yyyy
. Which is the best to do it?
I\'m doing this:
Your way is totally OK.You may try doing this:-
string res = "20130908";
DateTime d = DateTime.ParseExact(res, "yyyyMMdd", CultureInfo.InvariantCulture);
Console.WriteLine(d.ToString("MM/dd/yyyy"));
Just for reference from MSDN:-
The DateTime.ParseExact(String, String, IFormatProvider) method parses the string representation of a date, which must be in the format defined by the format parameter.