Skip to content

Instantly share code, notes, and snippets.

@bananafish911
Created October 15, 2016 09:23
Show Gist options
  • Save bananafish911/62afd599f499b840ad6ee4c49249bf1b to your computer and use it in GitHub Desktop.
Save bananafish911/62afd599f499b840ad6ee4c49249bf1b to your computer and use it in GitHub Desktop.
extension TimeInterval {
// builds string in app's labels format 00:00.0
func stringFormatted() -> String {
var miliseconds = self.roundTo(places: 1) * 10
miliseconds = miliseconds.truncatingRemainder(dividingBy: 10)
let interval = Int(self)
let seconds = interval % 60
let minutes = (interval / 60) % 60
return String(format: "%02d:%02d.%.f", minutes, seconds, miliseconds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment