Swift Get Current Hour

[Solved] Swift Get Current Hour | Swift - Code Explorer | yomemimo.com
Question : swift get current hour

Answered by : aris-g

let date = Date() // save date, so all components use the same date
let calendar = Calendar.current // or e.g. Calendar(identifier: .persian)
let hour = calendar.component(.hour, from: date)
let minute = calendar.component(.minute, from: date)
let second = calendar.component(.second, from: date)

Source : https://stackoverflow.com/questions/24137692/how-to-get-the-hour-of-the-day-with-swift | Last Update : Tue, 16 Jun 20

Question : swift get current hour

Answered by : aris-g

let hour = Calendar.current.component(.hour, from: Date())

Source : https://stackoverflow.com/questions/24137692/how-to-get-the-hour-of-the-day-with-swift | Last Update : Tue, 16 Jun 20

Question : swift get current hour

Answered by : aris-g

let formatter = DateFormatter()
formatter.dateFormat = "hh a" // "a" prints "pm" or "am"
let hourString = formatter.string(from: Date()) // "12 AM"

Source : https://stackoverflow.com/questions/24137692/how-to-get-the-hour-of-the-day-with-swift | Last Update : Tue, 16 Jun 20

Answers related to swift get current hour

Code Explorer Popular Question For Swift