我正在開發一個使用日期,月份,年份的應用程序。我想要當前的月份日期,因爲當前月份可能有28,29,30,31天。我試圖獲得當年的月份。但我不知道上面的代碼。這是我的代碼。如何獲取目標c中當前月份的日期?
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *today = [NSDate date];
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDateComponents *yearComponents = [currentCalendar components:NSYearCalendarUnit fromDate:today];
int currentYear = [yearComponents year];
for(int months = 0; months < 12; months++)
{
NSString *monthName = [NSString stringWithFormat:@"%@ %i",[[dateFormatter monthSymbols]objectAtIndex: months],currentYear];
NSLog(@"%@ %i",[[dateFormatter monthSymbols]objectAtIndex: months],currentYear);
[monthArray addObject:monthName];
}
我怎麼不能得到每個日期?從2013年10月1日到2013年10月31日 – Manimaran
有沒有辦法讓個人約會? – Isuru
http://stackoverflow.com/questions/8501502/getting-every-nsdate-for-this-month-as-nsstring –