Iphone 从xcode 4中的电话获取时间时出错?
我试图从手机时钟中提取时间,但无法使用此代码提取时间Iphone 从xcode 4中的电话获取时间时出错?,iphone,xcode4,Iphone,Xcode4,我试图从手机时钟中提取时间,但无法使用此代码提取时间 NSDate *today = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSInteger hour = [components hour]; NSInteger minute = [compo
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
用这个
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components =
[gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:today];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
您在代码中遗漏了一行。请使用此选项
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components =
[gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:today];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
你漏了一行代码