- NSDate *nowDate = [NSDate new];
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- // 根据时区名字获取当前时间,如果该时区不存在,默认获取系统当前时区的时间
- // NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Europe/Andorra"];
- // [formatter setTimeZone:timeZone];
- //获取所有的时区名字
- NSArray *array = [NSTimeZone knownTimeZoneNames];
- // NSLog(@"array:%@",array);
- //for循环
- // for(int i=0;i<[array count];i++)
- // {
- // NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:[array objectAtIndex:i]];
- // [formatter setTimeZone:timeZone];
- // NSString *locationTime = [formatter stringFromDate:nowDate];
- // NSLog(@"时区名字:%@ : 时区当前时间: %@",[array objectAtIndex:i],locationTime);
- // //NSLog(@"timezone name is:%@",[array objectAtIndex:i]);
- // }
- //快速枚举法
- for(NSString *timeZoneName in array){
- [formatter setTimeZone:[NSTimeZone timeZoneWithName:timeZoneName]];
- NSLog(@"%@,%@",timeZoneName,[formatter stringFromDate:nowDate]);
- }
- [formatter release];
- [nowDate release];
- //该片段来自于http://www.codesnippet.cn/detail/041220137744.html
来源: http://www.codesnippet.cn/detail/041220137744.html