Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DineshKachhot/3a741b8879fee7d1b53e37528e2afd23 to your computer and use it in GitHub Desktop.
Save DineshKachhot/3a741b8879fee7d1b53e37528e2afd23 to your computer and use it in GitHub Desktop.
Audio/Video Duration formate in Swift 4.2
import Foundation
extension TimeInterval {
struct DateComponents {
static let formatterPositional: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour,.minute,.second]
formatter.unitsStyle = .positional
formatter.zeroFormattingBehavior = .pad
return formatter
}()
}
var positionalTime: String {
return DateComponents.formatterPositional.string(from: self) ?? ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment