How can I get the last day of the current month as an NSDate
?
extension NSDate {
func lastDayOfMonth() -> NSDate {
let calendar = NSCalendar.currentCalendar()
let dayRange = calendar.rangeOfUnit(.Day, inUnit: .Month, forDate: self)
let dayCount = dayRange.length
let comp = calendar.components([.Year, .Month, .Day], fromDate: self)
comp.day = dayCount
return calendar.dateFromComponents(comp)!
}
}