How can you determine the hour, minute and second from NSDate class in Swift 3?
In Swift 2:
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.Hour, fromDate: date)
let hour = components.hour
Swift 3?
This might be handy for those who want to use the current date in more than one class.
Usage
For best useful I create this function:
You simply call it wherever you want like this:
this is the Output:
if want only the time simply change :
and this is the output:
and that's it...
Swift 4
Swift 4.2 & 5
Swift 3.0