Search code examples
iosswiftfscalendar

Get Current month and year from FSCalender -Swift


I am using FSCalender for ma project. I need to scroll the calender for getting next month.

I am using this code to get the change notification

 func calendarCurrentMonthDidChange(_ calendar: FSCalendar!) {
    print("Changed")

    print("ss",ss)
    // Do something
}

what I need is to get the current month and year form the calendar object..


Solution

  • You can use the calendar.currentPage to get the Date value. Then use Component

    let currentPageDate = calendar.currentPage
    
    let month = Calendar.current.component(.month, from: currentPageDate)
    
    print(month)