0

I am using FSCalender through cocoa pods. I simply want to get the selected date/month/year. I am only getting current date. I am getting details like this :-

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];  
    formatter.dateFormat = @"dd.MM.yyyy";  
    NSString *string = [formatter stringFromDate:[NSDate date]]; 
    NSLog(@"CurrentDate=%@",string);  

In string, I am getting output :- CurrentDate=08.02.2017

How to achieve this. Thanks in advance.

Vakas
  • 6,291
  • 3
  • 35
  • 47
Abhishek Sharma
  • 73
  • 3
  • 10

1 Answers1

2

There is a delegate method in FSCalendar for this

// FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
    // Do something
    // get year , month and day of selected date.

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date];

NSInteger day = [components day];
NSInteger month = [components month];
NSInteger year = [components year];

}

Here you will get a object of NSDate, and then you can convert it into your desired format.

Please read the full documentation of this library FSCalendar

To get day/Month/year from Date you can refer following Stack overflow answer :

Community
  • 1
  • 1
Wolverine
  • 4,264
  • 1
  • 27
  • 49