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
You can use this replacement:
demo
or better:
demo
You could do something like this:
Divide the time in 3 parts. Remove the leading zeroes from first part, if the the first part is empty remove the leading zeroes from the second part otherwise keep it. Then join all of them discarding the empty strings.
Another option is to use moment.js libary.
This supports formats such as
http://jsfiddle.net/8yqxh5mo/
If you use 1 h instead of two you will not get the leading 0.
h:mm:ss