You must Sign In to post a response.
  • Category: .NET

    How to convert a string to a timespan in

    I have a string which I want to convert toa time span object
    string sDuration = "00:18:09";

    Now I want to assign this value to a time span object.
    TImeSpan ts = new TimeSpan();
    ts = (TimeSpan)sDuration;

    but this type cast is not working.
  • #259714
    TimeSpan timeSpan = new System.TimeSpan();
    bool isTimeSpan = System.TimeSpan.TryParse(sDuration , out timeSpan); (if u r working in 2003 u wont have TryParse..u can use simply Parse method.TryParse returns false if the input string is not in correct format .)..

    Try it.It works


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.