用于BST而不是GMT + 1的NSDateFormatter

我想在我的时间轴上显示以下string:

“GMT / BST”

代码如下:

NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"zzz"]; timeZoneString = [NSMutableString stringWithFormat:@"%@ / %@",[dateformatter stringFromDate:startDate],[dateformatter stringFromDate:endDate]]; 

但是这给了“GMT / GMT + 01:00”

什么是将“GMT + 01:00”变成“BST”的NSDateFormatter代码? 我无法得到正确的格式化程序来做到这一点,试图z | zzz | z | zzz | v | v见… http://waracle.net/iphone-nsdateformatter-date-formatting-table/

结果发现在iOS中有48个时区缩写(例如'BST')。

 NSDictionary *tzDict = [NSTimeZone abbreviationDictionary]; 

这个数组中有419个时区名称(例如'Europe / London'):

 NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames]; 

tzDict包含时区名称子集的夏令时缩写。 所以algorithm是检查我们是否在DST中,然后看看tzDict是否有条目,并且否则使用

 [NSTimeZone abbreviation]; 

一般来说,这里有一些其他的时区话题。

夏令时和时区最佳实践

如何将tz数据库名称映射到城市和国家名称?

C#英国夏令时(BST)时区缩写

http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

目标c中的GMT时区转换