If I have an NSTimeInterval that is set to say 200.0, is there a way to convert that into 00:03:20, I was thinking I could initialise an NSDate with it and then use NSDateFo
Based on answer by @onmyway133 here is the Swift 4 version:
func format(duration: TimeInterval) -> String {
let formatter = DateComponentsFormatter()
formatter.zeroFormattingBehavior = .pad
if duration >= 3600 {
formatter.allowedUnits = [.hour, .minute, .second];
} else {
formatter.allowedUnits = [.minute, .second];
}
return formatter.string(from: duration) ?? "";
}