首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

获取世界各地时间步骤

2012-08-03 
获取世界各地时间方法??? NSDate *nowDate [NSDate new]??? NSDateFormatter *formatter??? ? [[NSDat

获取世界各地时间方法

??? 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];

热点排行