我想在我的时间轴上显示以下字符串:
“格林威治标准时间/英国夏令时”
代码如下:
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 包含时区名称子集的夏令时缩写。所以该算法将检查我们是否在 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
关于ios - BST 的 NSDateFormatter 而不是 GMT+1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40320814/