问题
I search and try this for a couple hour. I have 2 date picker. Let say fromDatePicker and untilDatePicker. I set the untilDatePicker to current date (ex: 12/06/17) and i want to set the fromDatePicker into first date of the current month (ex: 01/06/17) but i dont have any idea to set the untilDatePicker. I have read this but its not help me to much. Any sugest and answer will help for me. Thanks in Advance
回答1:
This is swift3 solution and how you set first day of current month in datePicker , if you need to get first of other month just change date variable with some day from that month
let date = NSDate()
let calendar = NSCalendar.current
let components = calendar.dateComponents([.year,.month], from: date as Date)
let startOfMonth = calendar.date(from: components)
self.datePicker.setDate(startOfMonth!, animated: true)
来源:https://stackoverflow.com/questions/44493102/swift-set-custom-dateday-only-in-datepicker