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 code is in fact the best (of course better using TryParseExact
), however looks like your input string is in the correct format (convertible to DateTime
), you just want to re-format it, I think using some string method will help. But I would like to use Regex
here:
string output = Regex.Replace(input, "^(\\d{4})(\\d{2})(\\d{2})$", "$2/$3/$1");
//E.g
input = "20130920";
output = "09/20/2013";