Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove leading zeros from time format

I am receiving a string in this format 'HH:mm:ss'. I would like to remove the leading zeros but always keeping the the last four character eg m:ss even if m would be a zero. I am formatting audio duration.

Examples:

00:03:15 => 3:15
10:10:10 => 10:10:10
00:00:00 => 0:00
04:00:00 => 4:00:00
00:42:32 => 42:32
00:00:18 => 0:18
00:00:08 => 0:08

like image 642
malimichael Avatar asked Mar 18 '17 19:03

malimichael


1 Answers

If you use 1 h instead of two you will not get the leading 0.

h:mm:ss

like image 192
Gaurav Joshi Avatar answered Sep 29 '22 04:09

Gaurav Joshi