Split time string with regex - Javascript String Operation

Javascript examples for String Operation:String Split

Description

Split time string with regex

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w w  w  .j  a  va  2s  .  c  om
var arr = ["10:28:51","00:00:59","01:25:59"];
var reg = /(\d+):(\d+):(\d)/, ret = [];
arr.forEach(function(v){
    ret = reg.exec(v);
    console.log(parseInt(ret[1]) + "h" + parseInt(ret[2]) + "m" + parseInt(ret[3]) + "s");
});
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials