嗨,我要计算两个日期的天数,我要申请休假的日期是相同的,所以差额应为“ 1”休假,而我的代码计算为“ 0”
我的代码:
fromDateTextField.text = 29-06-2019
toDateTextField.text = 29-06-2019
let startDate = fromDateTxtField.text
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
let formatedStartDate = dateFormatter.date(from: startDate!)
let currentDate = toDateTxtField.text
dateFormatter.dateFormat = "dd-MM-yyyy"
let formatedEndDate = dateFormatter.date(from: currentDate!)
print(formatedEndDate)
print(formatedStartDate)
let components1 = Set<Calendar.Component>([.day])
let differenceOfDate = Calendar.current.dateComponents(components1, from: formatedStartDate!, to: formatedEndDate!)
print (differenceOfDate.day)
我得到的输出是“ 0”