I receive a string in this format "7:00 am - 11:00 pm" representing start and end time. The string will always have two times. Now I need to format that to today's date & time so in above case it's easy. It comes to 18th March 7 AM - 18th March 11 PM but there is an edge case where time is like "7:00 am - 12:00 am", in this case it will need to be converted to 18th March 7 AM - 19th March 12 AM.
Now I can handle this using if :D. So whenever the second token is smaller than first token (e.g. "7:00 am - 02:00 am") I can increase the date of the second part.
string input = "7:00 am - 12:00 am";
List<DateTime> tokens = input.Split('-').Select(x => DateTime.Parse(x.Trim(), CultureInfo.GetCultureInfo("en-NZ"))).ToList();
if(tokens[1] < tokens[0]){
tokens[1] = tokens[1].AddDays(1);
}
But I would like to know if there is any builtin way in C# itself through Timespan, Datetime classes etc to handle it.
