How to extract hours, minutes and second from string in JavaScript

1 Answer

0 votes
const str = "10:44:21";
        
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:
   
10:44:21
   
*/

 



answered Dec 28, 2023 by avibootz

Related questions

1 answer 168 views
1 answer 126 views
2 answers 179 views
2 answers 196 views
2 answers 147 views
2 answers 147 views
...