Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.    
  3.     getHourSubHour('13:30', '17:59');
  4.  
  5.     function getHourSubHour(hs, he)
  6.     {
  7.         var sHour1 = he.split(":");
  8.         var sHour2 = hs.split(":");
  9.         var iSeconds1 = 0;
  10.         var iSeconds2 = 0;
  11.         var iSeconds3 = 0;
  12.  
  13.         sHour1[0] = parseInt(sHour1[0]);
  14.         sHour2[0] = parseInt(sHour2[0]);
  15.  
  16.         sHour1[1] = parseInt(sHour1[1]);
  17.         sHour2[1] = parseInt(sHour2[1]);
  18.  
  19.  
  20.         iSeconds1 = (sHour1[0] * 3600);
  21.         iSeconds1 += (sHour1[1] * 60);
  22.  
  23.         iSeconds2 = (sHour2[0] * 3600);
  24.         iSeconds2 += (sHour2[1] * 60);
  25.  
  26.         iSeconds3 = (iSeconds1 - iSeconds2);
  27.         GetMakeTime(iSeconds3);
  28.  
  29.     }
  30.  
  31.     function GetMakeTime(seconds)
  32.     {
  33.  
  34.         var
  35.         iHours = 0,
  36.             iMinutes = 0,
  37.             iSeconds = seconds,
  38.             sString;
  39.  
  40.         while (iSeconds > 59)
  41.         {
  42.             iSeconds -= 60;
  43.             ++iMinutes;
  44.         }
  45.  
  46.         while (iMinutes > 59)
  47.         {
  48.             iMinutes -= 60;
  49.             ++iHours;
  50.         }
  51.         if(iMinutes < 10)
  52.         {  
  53.             var sstr1 = '0' + iMinutes;
  54.         }
  55.         if(iHours < 10)
  56.         {  
  57.             var sstr2 = '0' + iHours;
  58.         }
  59.         sString = sstr2  + ':' + sstr1;
  60.         alert(sString);
  61.     }
  62. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement