I want to get firstdate、lastdate of month,I try
NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
[components setDay:1];
self.c
Swift 5 getting last day of month - base on different sources
// -------------------------------------------------------
// lastDayOfMonth
// -------------------------------------------------------
static func lastDayOfMonth(year:Int, month:Int) -> Int {
let calendar:Calendar = Calendar.current
var dc:DateComponents = DateComponents()
dc.year = year
dc.month = month + 1
dc.day = 0
let lastDateOfMonth:Date = calendar.date(from:dc)!
let lastDay = calendar.component(Calendar.Component.day, from: lastDateOfMonth)
return lastDay
}