问题
I'm trying to set the maximum date to be 7 days ahead of the current date ( today's date).
datePicker.maximumDate =
回答1:
I've figured it out.
var sevenDaysfromNow: Date {
return (Calendar.current as NSCalendar).date(byAdding: .day, value: 7, to: Date(), options: [])!
}
datePicker.maximumDate = sevenDaysfromNow
回答2:
I think this is easier:
datePicker.maximumDate = date.addingTimeInterval(604800)
604800 seconds are 7 days.
来源:https://stackoverflow.com/questions/47004269/how-to-set-a-maximum-date-for-date-picker-swift-4