func setDate(){
let start = "2016-04-18"
let end = "2017-02-13"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let startDate = dateFormatter.date(from: start)!
let endDate = dateFormatter.date(from: end)!
let cal = NSCalendar.current
let unit : Set<Calendar.Component> = [.day]
let daysBetween = cal.dateComponents(unit, from: startDate, to: endDate)
dayText.text = "\(daysBetween)"
print(daysBetween)
}
我有这个代码,我的问题是我得到以下文字:
日:301 isLeapMonth:false
我只想要该文本中的数字。