Format time as hh:mm:ss with leading zeros if needed

Taken from http://stackoverflow.com/a/12612778