我试图迅速获得本月的第一天和最后一天.
到目前为止,我有以下内容:
let dateFormatter = NSDateFormatter()
let date = NSDate()
dateFormatter.dateFormat = "yyyy-MM-dd"
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: date)
let month = components.month
let year = components.year
let startOfMonth = ("\(year)-\(month)-01")
Run Code Online (Sandbox Code Playgroud)
但我不知道如何获得最后的约会.有缺点的内置方法吗?显然它必须考虑到闰年等.