gpt4 book ai didi

ios - 日期选择器 startDate 和 endDate Swift 3

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:15 26 4
gpt4 key购买 nike

我只想显示 180 天的 UIDatePickerView 开始日期日历,当用户选择 180 天内的任何开始日期时,他将单击结束日期按钮,因此日期选择器应该只显示 89 天开始日期和选定的开始日期不应是结束日期

最佳答案

// Add A Button And Give them Connection
@IBOutlet weak var DateSelect: UIButton!

// Add "UIDatePicker" to your project and Give them connection
@IBOutlet weak var fromedatepicker: UIDatePicker!

// . and Make an Action Button to "UIDatePicker"
@IBAction func fromedatepicker(_ sender: Any) {
let calendar: NSCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!
let currentDate = NSDate()
let dateComponents = NSDateComponents()
let minDate = calendar.date(byAdding: dateComponents as DateComponents, to: currentDate as Date, options: NSCalendar.Options(rawValue: 0))

dateComponents.month = 3 //or you can change month = day(90)

let maxDate = calendar.date(byAdding: dateComponents as DateComponents, to: currentDate as Date, options: NSCalendar.Options(rawValue: 0))
self.fromedatepicker.maximumDate = maxDate
self.fromedatepicker.minimumDate = minDate

let dateFormatter = DateFormatter()

dateFormatter.dateFormat = "dd/MM/yyyy"
let strDate = dateFormatter.string(from: fromedatepicker.date)
print(strDate)

DateSelect.DateSelect.titleLabel?.text = strDate
}

关于ios - 日期选择器 startDate 和 endDate Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45428711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com