Home > DeveloperSection > Forums > How to parse string contains time of day in c#?
Ashish Pandey

Total Post:128

Points:898
Posted on    November-10-2014 11:49 PM

 ASP.Net C#  Exception  Time  DateTime 
Ratings:


 1 Reply(s)
 593  View(s)
Rate this:

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";



Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    November-11-2014 2:03 AM

Try this:

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


Don't want to miss updates? Please click the below button!

Follow MindStick