HOW TO PARSE STRING CONTAINS TIME OF DAY IN C#?

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
 890  View(s)
Ratings:
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";

  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: How to parse string contains time of day in c#?

    Try this:

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!