在下面的例子中,它会始终在用户的设备上显示当前时间,或者它将显示GMT,并且我需要获取和设置时区?iOS当前时间需要时区?
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components =
[gregorian components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:today];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
NSLog(@"hour %d", hour);
NSLog(@"minute %d", minute);
NSLog(@"second %d", second);
不需要转换为时区。但这也取决于你的需求。 – Vvk