在下面的例子中,它會始終在用戶的設備上顯示當前時間,或者它將顯示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