所以我试图获取特定时区的时间并将其作为标签显示在我的故事板上。显示的时间是正确的,但它不会随着时间的推移而更新。我错过了什么? 这是代码:
- (void)viewDidLoad {
# pragma mark TimeZones
NSDate *now = [NSDate date];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"hh:mm"];
[formatter2 setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Sydney"]];
NSLog(@"%@",[formatter2 stringFromDate:now]); //--> 11:54 PM
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Paris"]];
NSLog(@"%@",[formatter2 stringFromDate:now]);
NSString *strSelectedDate= [formatter stringFromDate:now];
self.zone.text = strSelectedDate;
}