How to parse string contains time of day in c#?

I try to cast a string to time span but i get the following exception :

Input string was not in a correct format.

My code :

rad_from_time.SelectedTime = TimeSpan.Parse(pro[0].FromTime)

pro[0].FromTime = "1:00 AM";

Last updated:11/11/2014 2:03:30 AM

1 Answers

Manoj Bhatt
Manoj Bhatt

Try this:

rad_from_time.SelectedTime = DateTime.ParseExact(pro[0].FromTime, "h:mm tt", CultureInfo.InvariantCulture).TimeOfDay;