Reputation: 9787
I have an input in seconds I store it in a var:
var totalTime = 60
I want to show it with 2 digits for minutes and 2 digits for seconds:
01:00
What I have tried:
let minutes = String(totalTime / 60)
let seconds = String(totalTime % 60)
label.text = minutes + ":" + seconds
This gives me: 1:0 But I want 01:00
I tried and It does not work:
label.text = String(format: "%02d:%02d", minutes, seconds)
Upvotes: 0
Views: 638
Reputation: 236260
The problem with your second approach is that it expects an integer and you are passing a string.
let minutes = totalTime / 60
let seconds = totalTime % 60
label.text = String(format: "%02d:%02d", minutes, seconds)
Upvotes: 3