How to convert string into time format in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sayli
    New Member
    • Aug 2007
    • 1

    How to convert string into time format in asp.net

    I have 00:01:00 in a string.
    I want to convert it into time format.
    How can i do this?
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I assume that this represents 1 min. Either way split the string and convert to time. HTH.

    Comment

    • chazcross
      New Member
      • Feb 2007
      • 31

      #3
      im not sure if this is what you want

      Code:
      string s = "00:01:00";
      DateTime d = DateTime.Parse(s);
      Response.Write(d.ToShortTimeString());
      this will return 12:01 AM

      Comment

      • baldrex
        New Member
        • Jun 2007
        • 8

        #4
        hmm...

        I have something similar to this but in my case this will not work. I have a text field storing the value in mins in this format 000100 representing 1 min.

        I need to break this into a time reference 00:01:00 so that I can use it to calculate total time spent.

        I have tried several different date/time functions but they all add the date, which I do not need.

        question is: is there a way to convert this text into a time only field ?

        i.e. Duration time/duration
        005005 ... 00:50:05
        000905 ... 00:09:05
        001500 ... 00:15:00

        total 01:14:10

        thanks for you help!
        Last edited by baldrex; Aug 30 '07, 01:26 PM. Reason: wrong place moving to new post

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          TimeSpan object.
          (Note: They inter-twine very well with the DateTime object)
          But you should be able to create a timespan object from a number of secods or minutes, or whatever

          Comment

          Working...