我目前正在将EST时区的计时器格式化为设备时区
一切都在模拟器上完美运行,定时器会转换,但是一旦我在设备上运行它,它只会返回(null)
。
时间字符串看起来像11:00 AM ET
NSString *timeString = time.time;
timeString = [timeString stringByReplacingOccurrencesOfString:@" ET" withString:@""];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mma"];
NSDate* dateFromString = [dateFormatter dateFromString:timeString];
NSDateFormatter* df_utc = [[NSDateFormatter alloc] init];
[df_utc setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]];
[df_utc setDateFormat:@"hh:mma"];
NSDateFormatter* df_local = [[NSDateFormatter alloc] init];
[df_local setTimeZone:[NSTimeZone localTimeZone]];
[df_local setDateFormat:@"hh:mma"];
NSString *ts_utc_string = [df_utc stringFromDate:dateFromString];
NSString *ts_local_string = [df_local stringFromDate:dateFromString];
NSLog(@"UTC TIME: %@",ts_utc_string);
NSLog(@"LOCAL TIME: %@",ts_local_string);
在设备上它是NSLogs(null),但在模拟器上它会记录时间。