2014-02-07 29 views
0

我想在我的时间轴显示以下字符串:NSDateFormatter为BST,而不是GMT + 1

“GMT/BST”

下面的代码:

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

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

什么是NSDateFormatter号码关闭 “GMT + 01:00” 到 “BST”?我不能得到正确的格式化程序来做到这一点,试图z | zzz | Z | ZZZ | v | V看到... http://waracle.net/iphone-nsdateformatter-date-formatting-table/

+0

嗯,如果'knownTimeZoneNames'不显示你想要的名称,它可能不是在/ usr/share/zoneinfo中。 –

+0

'欧洲/ London'是'knownTimeZoneNames'最接近的一次。我想我可以以编程方式更改字符串'BST'如果='GMT + 01:00'。但是这似乎有点破解。 –

+0

(如果你尝试设置时区为“GMT/BST”会发生什么?) –

回答

0

原来有一个内置的48个时区缩写(例如' BST')。

NSDictionary *tzDict = [NSTimeZone abbreviationDictionary]; 

有419时区名称此数组中的数组(如“欧洲/伦敦):

NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames]; 

tzDict包含夏令时的缩写的时区名称的一个子集。因此,该算法将检查如果我们在DST,然后再看是否有tzDict的条目,并且替补多说如果还是不行,请

[NSTimeZone abbreviation]; 

这里是时区其他几个主题一般。

Daylight saving time and time zone best practices

How can I map tz database names to city and country names?

C# british summer time (BST) timezone abbreviation

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

GMT timezone conversion in objective c