用于BST的NSDateFormatter而不是GMT + 1 [英] NSDateFormatter for BST instead of GMT+1

查看:108
本文介绍了用于BST的NSDateFormatter而不是GMT + 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to display the following string on my time axis:

GMT / BST

这是代码:

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

但是这给出了GMT / GMT + 01:00

But this gives "GMT/GMT+01:00"

将GMT + 01:00转换为BST的NSDateFormatter代码是什么?尝试z | zzz | Z | ZZZ | v | V看看我无法找到合适的格式化程序... http://waracle.net/iphone-nsdateformatter-date-formatting-table/

What is the NSDateFormatter code to turn "GMT+01:00" into "BST" ? I can't get the right formatters to do this, having tried z|zzz|Z|ZZZ|v|V see... http://waracle.net/iphone-nsdateformatter-date-formatting-table/

推荐答案

原来在iOS中有48个时区缩写(例如'BST')的内置数组。

Turns out there is a built in array of 48 time zone abbreviations (e.g. 'BST') in iOS.

NSDictionary *tzDict = [NSTimeZone abbreviationDictionary]; 

此阵列中有419个时区名称(例如欧洲/伦敦):

There is an array of 419 time zone names in this array (e.g. 'Europe/London'):

NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames];

tzDict包含时区名称子集的夏令时缩写。因此算法将检查我们是否在DST中,然后查看tzDict是否有条目,并替换该条目或如果没有,请使用

tzDict contains the abbreviations for daylight saving time for a subset of time zone names. So the algorithm would be to check if we are in DST, then see if tzDict has an entry, and subsitute that or if not, use

[NSTimeZone abbreviation];

以下是一些关于时区的其他主题。

Here are a few other topics on time zones in general.

夏令时和时区最佳做法

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

C# british summer time(BST)timezone abbreviation

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

目标c中的GMT时区转换

这篇关于用于BST的NSDateFormatter而不是GMT + 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆