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 255 views
1 answer 204 views
2 answers 295 views
2 answers 308 views
2 answers 267 views
2 answers 260 views
...