Check out example codes for "swift get current hour". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

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

Code Example 3

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)

Learn ReactJs, React Native from