I'm trying to use the new Foundation formatters. To format a Date
, I can do something like this:
Date.now.formatted(.dateTime.hour().minute().second())
// 5:03:17 PM
However, I'm trying to use this new API to replace the DateComponentsFormatter
:
let duration: TimeInterval = 0
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .positional
formatter.allowedUnits = [.minute, .second]
formatter.zeroFormattingBehavior = [.pad]
let formattedDuration = formatter.string(from: 0)
// 00:00
How can I use the new Foundation formatters API formatted
instead of DateComponentsFormatter
?
DateComponentsFormatter
can accept aTimeInterval
and was wondering how to use the new Foundation formatter. – Reive