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

1 Answer

0 votes
const str: string = "12:26:41";
        
const arr: string[] = str.split(":");
        
const hours: number = parseInt(arr[0].trim());
const minutes: number = parseInt(arr[1].trim());
const seconds: number = parseInt(arr[2].trim());
        
console.log(hours + ":" + minutes + ":" + seconds);




  
/*
run:
   
"12:26:41" 
   
*/

 



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
...