在日历Tapku上标记日期

时间:2013-09-30 13:10:39

标签: nsmutablearray nsarray tapku

我有以下api。我需要标记我在这里的日子。但图书馆日期的格式是这样的:

@"2013-08-12 00:00:00 +0000"  

如何在下面添加我的api,就像这个日期格式一样?

{
      "year": "2013",
      "month": "08",
      "calendarDays":  [ "17", "24"  ]
}

我做过类似的事情,但这对我没用。

//calElem year --> year
//[calElem month] --> month
//self.CalenderDaysArray -->calendarDays


for(int i=0; i<[self.CalenderDaysArray count]; i++){

      self.CalenderDaysArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%@-%@-%@ 00:00:00 +0000",[calElem year],[calElem month],[self.CalenderDaysArray objectAtIndex:i], nil]];

}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我用以下代码解决了我的问题:

  NSMutableArray *datearray=[NSMutableArray array];
            NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

            NSDateComponents *todayComponents = [[NSDateComponents alloc] init];
            NSArray *myStringArr=[self.CalenderDays objectAtIndex:0];

            for(int i=0; i<myStringArr.count; i++){

                    todayComponents.year = [[calElem year]intValue];
                    todayComponents.month = [[calElem month] intValue];
                    todayComponents.day = [[myStringArr objectAtIndex:i]intValue];
                    todayComponents.hour = 00;
                    todayComponents.minute = 00;
                    todayComponents.second= 00;
                    NSDate *today = [calendar dateFromComponents:todayComponents];
                    [datearray addObject:[self getdateCalendar:today]];


            }