get hours from time in swift code example
Example 1: swift get current hour
let hour = Calendar.current.component(.hour, from: Date())
Example 2: swift get current hour
let formatter = DateFormatter()
formatter.dateFormat = "hh a" // "a" prints "pm" or "am"
let hourString = formatter.string(from: Date()) // "12 AM"