Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

整数を00:00:00にさせる方法を考えてる時のメモ

More than 3 years have passed since last update.
mport UIKit

var count = 4762
let day = count / (24 * 3600)
let hour = count / 3600
let minute = (count - hour * 3600) / 60
let second = count - (hour * 3600 + minute * 60)

print("まだ\(count)秒です。")

func dayTime() {
    print("\(day)日です。")
}

dayTime()

func hourTime() {
//    let hour = count / 3600
    print("\(hour)時間です。")
}

hourTime()

func minuteTime() {
//    let minute = (count - hour * 3600) / 60
    print("\(minute)分です。")
}

minuteTime()

func secondTime() {
    print("\(second)秒です。")
}

secondTime()
print(String(format: "%02d:%02d:%02d", hour, minute, second))

func countDown() {
    count -= 1
    timeFormat(count: count)
//    print("残り\(count)秒です。")
//    print(String(format: "%02d:%02d:%02d", hour, minute, second))

}

func timeFormat(count:Int) {
    let h = count / 3600
    let m = (count - h * 3600) / 60
    let s = count - (h * 3600 + m * 60)
    print(String(format: "%02d:%02d:%02d", h, m, s))
}

countDown()


結果こうなりました↓↓↓

まだ4762秒です。
0日です。
1時間です。
19分です。
22秒です。
01:19:22
01:19:21

varの値を変えるとそれを直してくれます。
最近で一番頭使ってたかも・・・

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away