Saneesh
Saneesh

Reputation: 1864

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..

Upvotes: 0

Views: 7012

Answers (2)

Aakash
Aakash

Reputation: 2269

You can use this as mentioned in https://github.com/WenchaoD/FSCalendar/issues/508

    let values = Calendar.current.dateComponents([Calendar.Component.month, Calendar.Component.year], from: self.calendar.currentPage)
CURRENT_YEAR = values.year
CURRENT_MONTH = values.month

let range = Calendar.current.range(of: Calendar.Component.day, in: Calendar.Component.month, for: self.calendar.currentPage)
TOTAL_DAYS = range.count

Upvotes: 1

xmhafiz
xmhafiz

Reputation: 3538

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)

Upvotes: 14

Related Questions