Add hours:min from TextField to hours:min from other bigger 24h



  • Hello,
    I have TextField with hours:minutes format (example 625:45) and the other with 200:30 and I need to obtain 826:15 on the third one, how can I do that?...

    thanks you for your help



  • I found myself how to do lol

    functionadd.js

    function addhours(str1,str2)
    {
    
        var res1 = str1.split(":")
        var hours1 = parseInt(res1[0]);
        var minutes1 = parseInt(res1[1]);
    
        var res2 = str2.split(":")
        var hours2 = parseInt(res2[0]);
        var minutes2 = parseInt(res2[1]);
         var res3 = hours1 + hours2
         var res4 = minutes1 + minutes2
    
          if (res4>= 60)
          {
              res4 = res4 - 60;
              res3 = res3 + 1;
          }
          if (res4<=9)
          {
              res4 = "0"+ res4
          }
    
          var timeres = res3 + ":" + res4;
          return timeres ;
    }
    

    file.qml

    
    import "functionadd.js" as JS1
    
    
    resulthourInput.text = JS1.addhours(hour1Input.text,hour2Input.text);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.