我一直在开发适用于iPhone的天气应用程序,一切都在iOS5上正常运行,但iOS6上显示的日子有些奇怪....
但奇怪的是,此代码返回satuarday instead of monday sunday instead of tuesday
等等......但它在iOS 5上工作正常
我使用以下方法显示一周中的日期..
-(NSString*)calculateDayOfTheWeek:(NSString *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
// [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[formatter setDateFormat:@"YYYY-MM-dd"];
NSDate *date1 = [formatter dateFromString:date];
// NSCalendar *gregorian = [NSCalendar currentCalendar];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [gregorian components:NSWeekdayCalendarUnit fromDate:date1];
int w = [comps weekday];
// NSLog(@"%i",w);
if(w == 1)
return @"Sun";
else if (w == 2)
return @"Mon";
else if(w == 3)
return @"Tue";
else if (w == 4)
return @"Wed";
else if(w == 5)
return @"Thu";
else if (w == 6)
return @"Fri";
else if (w == 7)
return @"Sat";
else
return @"";
}
答案 0 :(得分:0)
ahhhhh .....我想出来......他们已将日期格式从YYYY-MM-dd
更改为yyyy-MM-dd
...
这可能是对某人的帮助......