Hi I am getting the value of time as a string. The number which i am getting is in the seconds. Now i want to convert the Seconds to minutes by using swift3.
The Seconds which i am getting is: 540 this is in seconds.
Now i want to convert the seconds to the minutes. For example it should show as 09:00 .
How to achieve this using Swift3 code. Currently i am not using any conversion code.
let duration: TimeInterval = 7200.0
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .positional // Use the appropriate positioning for the current locale
formatter.allowedUnits = [ .hour, .minute, .second ] // Units to display in the formatted string
formatter.zeroFormattingBehavior = [ .pad ] // Pad with zeroes where appropriate for the locale
let formattedDuration = formatter.string(from: duration)
Here is one method:
If you want your duration in seconds to be formatted as a "time of day," change the format string to:
Now, the resulting string should be:
This will vary, of course, based on locale.