我正在做一些天气应用程序,因为我想显示 4 天的预报,即从当天到接下来的 3 天。我得到了今天,代码是
NSCalendar* cal = [NSCalendar currentCalendar];
NSDateComponents* comp = [cal components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
// 1 = Sunday, 2 = Monday, etc.
NSInteger day0 = comp.weekday;
NSLog(@"My DAY is %i", day0);
NSString *str;
NSMutableString *myString = [NSMutableString string];
str = [NSString stringWithFormat:@"%d",day0]; //%d or %i both is ok.
[myString appendString:str];
NSLog(@"My DAY is %@", myString);
输出为 6 即周五 .... 很酷
我怎样才能在不增加当天的情况下获得第二天...我试图增加当天,但问题是,如果我将当天的日期设为 7,它会增加到 8,在平日没有这样的事情对..我是xcode的新手..帮帮我....