I have a program that converts an irregular date and time string to a DateTime system.
However, since the system does not recognize irregular strings, the .ParseExact, toDateTime, and TryParse methods did not work.
There are only 2 types of date strings that a program should convert:
Thu Dec 9 05:12:42 2010
Mon Dec 13 06:45:58 2010
Note that a single date has a double spacing, which I used the .replace method to convert a single date to Thu Dec 09 05:12:42 2010.
Can someone consult on codes? Thank!
Codes:
String rb = re.Replace(" ", " 0");
DateTime time = DateTime.ParseExact(rb, "ddd MMM dd hh:mm:ss yyyy", CultureInfo.CurrentCulture);
Console.WriteLine(time.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
source
share