On Apple developer docs, there is Custom Section Titles (https://developer.apple.com/library/ios/samplecode/DateSectionTitles/Introduction/Intro.html) where it obtains the year and month.
I would like to grab the day so I can build a section title that has the day, month and year.
How would I grab the day from this code?
code:
/*
Section information derives from an event's sectionIdentifier, which is a string representing the number (year * 1000) + month.
To display the section title, convert the year and month components to a string representation.
*/
static NSDateFormatter *formatter = nil;
if (!formatter)
{
formatter = [[NSDateFormatter alloc] init];
[formatter setCalendar:[NSCalendar currentCalendar]];
NSString *formatTemplate = [NSDateFormatter dateFormatFromTemplate:@"MMMM YYYY" options:0 locale:[NSLocale currentLocale]];
[formatter setDateFormat:formatTemplate];
}
NSInteger numericSection = [[theSection name] integerValue];
NSInteger year = numericSection / 1000;
NSInteger month = numericSection - (year * 1000);
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.year = year;
dateComponents.month = month;
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
NSString *titleString = [formatter stringFromDate:date];
From the
Here in the above posted code It is a section info that you are getting.
And section means name of the Month and Year only, because you are fetching here only Month and Year, you are not fetching the date so, you will not have Day.
Yew but through "APIEvent" and time stamp you can have day components..