这必须涉及UTC(GMT)与贵时区之间的时间区差异(可能位于GMT+2)。 NSDate is in UTC byault. 因此[NSDate Day]可以偏离当地时间。
The following code should output Jan 1, 2012:
NSDateF或matter *dateF或matter = [[NSDateF或matter alloc] init];
[dateF或matter setDateF或mat:@"yyyy zzz"];
NSLog(@"**> %@",[dateF或matter dateFromString:@"2012 GMT"]);
[dateF或matter release];
或
NSDateF或matter *dateF或matter = [[NSDateF或matter alloc] init];
[dateF或matter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateF或matter setDateF或mat:@"yyyy"];
NSLog(@"NSDate : %@",[dateF或matter dateFromString:@"2012"]);
[dateF或matter release];