Adam Strike Adam Strike - 8 months ago 39
Swift Question

How do I get just the time from an NSDate object?

Say for example my Date (formerly NSDate) object was created as the 12 June 2016 at 14:23, how would I extract just that 14:23 from my Date object? Basically some thing like



According to an answer on How to get time (hour, minute, second) in Swift 3 using NSDate?:

let date = Date()
let calendar = Calendar.current

let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)
let seconds = calendar.component(.second, from: date)
print("hours = \(hour):\(minutes):\(seconds)")