List of timezone abbreviations using xcode

百般思念 提交于 2019-12-25 12:08:33

问题


I have retrieved a list of all the time zones using this function and storing them in an array :

    timeZoneElements = [NSTimeZone knownTimeZoneNames] ;

I want to get the list of abbreviations , for example : GMT+1 … is there any easy and quick way to do that ?
Many thanks

Edit 1 : This solution shows the timezones like follows : Asia/Beirut … therefore i need to show instead the GMT+2 label ..


回答1:


Try This,

NSMutableArray *timeZoneArray  = [[NSMutableArray alloc] initWithArray:[NSTimeZone knownTimeZoneNames]];
NSMutableArray *abbreviationArray = [[NSMutableArray alloc] init];

for (int count=0; count < [timeZoneArray count]-1; count=count+1)
{
    [abbreviationArray addObject:[[NSTimeZone timeZoneWithName:[timeZoneArray objectAtIndex:count]] abbreviation]];
}

NSLog(@"Abbreviation : %@",abbreviationArray);


来源:https://stackoverflow.com/questions/23198439/list-of-timezone-abbreviations-using-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!