3

如何获取当前日历的开始和结束日期?

从屏幕截图中,我需要得到 2017 年 9 月 24 日和 2017 年 11 月 4 日。

谢谢![在此处输入图像描述] 1

4

2 回答 2

2
var dateArray = [Date]()
for cell:FSCalendarCell in calendar.visibleCells() {
  if cell.isPlaceholder {
    dateArray.append(calendar.date(for: cell)!)
  }
}

calendar.select(dateArray.min())
calendar.select(dateArray.max())
于 2017-07-25T11:21:49.063 回答
1

这是查看第一个和最后一个可见日期的方法

let startDate: Date?
let endDate: Date?
if self.calendar.scope == .week {
    startDate = self.calendar.currentPage
    endDate = self.calendar.gregorian.date(byAdding: .day, value: 6, to: startDate)
} else { // .month
    let indexPath = self.calendar.calculator.indexPath(for: self.calendar.currentPage, scope: .month)
    startDate = self.calendar.calculator.monthHead(forSection: (indexPath?.section)!)!
    endDate = self.calendar.gregorian.date(byAdding: .day, value: 41, to: startDate)
}

答案最初在这个线程中提到

于 2020-10-07T13:28:28.793 回答