BST的NSDateFormatter,而不是GMT + 1

问题描述 投票:0回答:2

我想在我的时间轴上显示以下字符串:

“” 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 iphone nsdate nsdateformatter
2个回答
1
投票

结果是在iOS中内置了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


0
投票

我花了一天的时间,并希望确保其他人不会挂在上面。

© www.soinside.com 2019 - 2024. All rights reserved.