There's already an identifier for this: $duration(t,[n])

t = time in seconds
n is an optional parameter of either '2' or '3'. 2 will not show the seconds if there are any. 3 will give an output in the hh:nn:ss form.

You can use a simple $gettok on the output if you need to do any parsing.