How to extract hours, minutes and second from string in Node.js

1 Answer

0 votes
const str = "11:58:35";
        
const arr = str.split(":");
        
const hours = parseInt(arr[0].trim());
const minutes = parseInt(arr[1].trim());
const seconds = parseInt(arr[2].trim());
        
console.log(hours + ":" + minutes + ":" + seconds);




  
/*
run:
   
11:58:35
   
*/

 



answered Dec 28, 2023 by avibootz

Related questions

1 answer 149 views
1 answer 146 views
1 answer 115 views
2 answers 166 views
2 answers 180 views
...