I have a time string as 12:48 AM. I want to convert this string into TimeSpan to append with DateTime Object. Currently I am trying the following snippets.
string format = "dd/MM/yyyy";
CultureInfo provider = CultureInfo.InvariantCulture;
var date = DateTime.ParseExact(dateValue, format, provider);
string timeFormate = "H:mm AM";
string timeValue = "12:48 AM";
var time = TimeSpan.ParseExact(timeValue,timeFormate,provider);
DateTime launchDate = date + time;
I am getting
Input string was not in a correct format
exception at line
var time = TimeSpan.ParseExact(timeValue,timeFormate,provider);
Please suggest me how to convert my specified string into time.
You need to parse that time into
DateTimeand then simply extract theTimeOfDayout of it when appending to the original date:OUTPUT: