斯威夫特两个日期之间的3天

时间:2017-02-13 20:30:57

标签: swift date

    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

我只想要该文本中的数字。

0 个答案:

没有答案