nsdate - Getting the month in DateComponents in iOS -
this question has answer here:
- ios: how proper month name number? 10 answers
i month datecomponents.
my code looks this:
nsdate *date = [nsdate date]; nsdatecomponents* datecomponents = [[nscalendar currentcalendar] components:nsyearcalendarunit|nsmonthcalendarunit|nsdaycalendarunit fromdate:date]; nsstring *month = [nsstring *stringwithformat:@"%i",datecomponents.month];
but month integer, month in format of mm or example: november.
how do it?
int monthnumber = 11; nsdateformatter *df = [[nsdateformatter alloc] init]; nsstring *monthname = [[df monthsymbols] objectatindex:(monthnumber-1)];//because dateformatter zero-based
Comments
Post a Comment