2017-06-18 7 views
0

iOSには、時刻/日付をフォーマットするAPIがあります。iOSで時間デルタをフォーマットするAPI

しかし、私は時間デルタ(endtime - starttimeを意味する)を持っています。私はそれをhh:mm:ssの形式でフォーマットしたい。

私はこれに使用できるiOS APIはありますか?

+1

は[DateComponentsFormatter](https://developer.apple.com/documentation/foundation/datecomponentsformatter)それを行います。 – Paulw11

答えて

1

あなたは文字列にNSTimeInterval値を変換するためにDateComponentsFormatterを使用することができます。

let f = DateComponentsFormatter() 
f.allowedUnits = [.hour, .minute, .second] 
f.unitsStyle = .positional 
f.zeroFormattingBehavior = .pad 
let result = f.string(from: 1000) // "0:16:40" 
関連する問題