Can any one please help me how to select date and print on label
@vishalofficial96 you can implement _FSCalendarDelegate_ and use
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
@vishalofficial96 Watch the sample projects,
@descorp and @Husseinhj thank you its is helpfull to me
I am using this library, but this method returns the previous day to me rather than actual selected date. For ex: I am selecting 25th April on calendar view, but in this method I receive 24th April. Any possible solutions?
@priya1588 you have to convert time From IST to UTC
@priya1588 Show this simple code
cell.lblStartTime.text = Utilities.getFormatedTimeInStringGMT(dateTime: Utilities.localDateFromUTC(timestamp: 1523339900))
Hi @priya1588.
Unfortunately, @vishalofficial96 answer is not fully correct.
NSDate only represents an absolute point in time. It has no concept of timezone.
The date parameter from calendar didSelectDate is a 00:00 of a specific date. When you _po_ the object or compare it with the other _NSDate_ (current time, for example) some conversion of _NSDate_ into _String_ or _Int_ have to be made, so, by default, system assume that it is UTC timestamp and represent it as a local time (that is where you have an issue, unless you live in GMT).
So to properly compare two NSDate you might need to use _NSDateComponents_.
For example:
- (NSComparisonResult)compareDatesWith:(NSDate*)otherDate {
NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents* comp1 = [calendar components:unitFlags fromDate:self];
NSDateComponents* comp2 = [calendar components:unitFlags fromDate:otherDate];
NSInteger comparison = [comp1 year] * 10000 + [comp1 month] * 100 + [comp1 day] -
([comp2 year] * 10000 + [comp2 month] * 100 + [comp2 day]);
return comparison > 0 ? NSOrderedDescending : comparison < 0 ? NSOrderedAscending : NSOrderedSame;
}
Most helpful comment
@vishalofficial96 you can implement _FSCalendarDelegate_ and use
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition