Str*_*rer 15 iphone xcode init nsdate
我需要将NSDate设置为iPhone App的特定日期,时间和时区.
下面的示例代码在iOS 4上运行正常,因为在iOS 4中引入了setTimeZone.如何在不使用setTimeZone的情况下轻松地将NSDate设置为日期,时间和时区,以便可以在iOS 3.0设备上使用?
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:2010];
[comps setMonth:8];
[comps setDay:24];
[comps setHour:17];
[comps setMinute:5];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"] ];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *referenceTime = [cal dateFromComponents:comps];
Run Code Online (Sandbox Code Playgroud)
猜猜这应该很简单,但不知何故NSDate,组件和日历和我不是好朋友......