Forum Discussion

krkarthik_info's avatar
krkarthik_info
Frequent Contributor
7 years ago
Solved

Is there any internal method to convert hh:mm:ss to seconds

Hi,

 

I am using StopWatch object to measure the time taken to open a file in my test application. StopWatch.toString() method returns the time taken in the string format hh:mm:ss. 

 

I wanted to convert that returned time to seconds. Can anyone suggest me a possible solution to achieve this.

 

Thanks in advance.

 

Thanks,

Karthik K R

  • StopWatch.Split() or StopWatch.Stop() both return the elapsed time as an integer of milliseconds.  Take that number, divide by 1000 and convert to a string and you have your number of seconds.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    StopWatch.Split() or StopWatch.Stop() both return the elapsed time as an integer of milliseconds.  Take that number, divide by 1000 and convert to a string and you have your number of seconds.

    • krkarthik_info's avatar
      krkarthik_info
      Frequent Contributor

      Thanks Robert and Shankar for the solutions.

       

      Thanks,

      Karthik K R

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    I don't think we have direct internal method to achieve this scenarios. I'm using below code to convert it.

     

    function test12()
    {
          var tempTime = aqConvert.StrToTime("00:25:54");
          Log.Message(convertTimetoSeconds(tempTime));
    } 
    
    function convertTimetoSeconds(timeObj)
    {
          //Parameter should be a time object     
          var hours = aqDateTime.GetHours(timeObj);
          var minutes = aqDateTime.GetMinutes(timeObj);
          var seconds = aqDateTime.GetSeconds(timeObj);
          
          var totalMinues = minutes + (hours * 60);
          var totalseconds = seconds + (totalMinues * 60);
          
          return totalseconds;
    //if you want to return minutes then
    //return totalMinues; }