I'm trying to format to MM:SS
using NSDateComponentsFormatter
:
let formatter = NSDateComponentsFormatter()
formatter.zeroFormattingBehavior = .Pad
formatter.allowedUnits = .CalendarUnitMinute | .CalendarUnitSecond
let time: NSTimeInterval = 5
let timeText = formatter.stringFromTimeInterval(time)
The problem is, that even though I specified .Pad
, the result is 0:05
instead of 00:05
.
Here's the relevant piece from Apple's documentation:
static var Pad: NSDateComponentsFormatterZeroFormattingBehavior { get }
// Off: "1:0:10", On: "01:00:10"
I've tried to add .CalendarUnitHour
just to try it and got H:MM:SS
instead of HH:MM:SS
despite what the documentation says.
How can I pad the very first number as shown in the documentation?