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 mydate.time
.
Asked
Active
Viewed 93 times
-3

Wyetro
- 8,439
- 9
- 46
- 64

Adam Strike
- 356
- 1
- 4
- 16
-
Your link is helpful however it isn't in Swift 3. `.CalendarUnitHour` and `.CalendarUnitMinute` are not accepted anymore. – Adam Strike Sep 08 '16 at 18:23
-
Your post is tagged as just Swift, not Swift 3. – Wyetro Sep 08 '16 at 18:24
1 Answers
0
Here's a handy extension so you use let time = Date().time
extension Date {
var time: String {
let calendar = Calendar.current
let components = calendar.dateComponents([.hour, .minute], from: self)
return "\(components.hour!):\(components.minute!)"
}
}

Callam
- 11,409
- 2
- 34
- 32