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
.
1 Answer
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!)"
}
}
-
-
-
-
-
@MartinR yes, after I edited if that's what you're getting at– CallamCommented Sep 8, 2016 at 19:21
.CalendarUnitHour
and.CalendarUnitMinute
are not accepted anymore.