NSTimezone如何将CST设置为nsdateformater

时间:2011-09-28 04:43:42

标签: iphone nsdateformatter nstimezone

所有

我是ios编程的新手。 我想在方法中设置CST

[dateFormatter setTimeZone:]

我创建了一个示例项目来获取所有已知的时区 代码在这里:

NSArray *timeZoneNames = [NSTimeZone knownTimeZoneNames];

for (NSTimeZone *timezon in timeZoneNames) {

    NSLog(@"%@",timezon);
}

它给出了以下结果:

[会议开始于2011-09-28 09:50:28 +0530。] 2011-09-28 09:50:29.535 Timezonetest [10352:207]非洲/阿比让

2011-09-28 09:50:29.537 Timezonetest [10352:207]非洲/阿克拉

2011-09-28 09:50:29.537 Timezonetest [10352:207]非洲/ Addis_Ababa

2011-09-28 09:50:29.538 Timezonetest [10352:207]非洲/阿尔及尔

........................

........................

........................

........................

2011-09-28 09:50:29.765 Timezonetest [10352:207] Pacific / Pago_Pago

2011-09-28 09:50:29.766 Timezonetest [10352:207] Pacific / Palau

2011-09-28 09:50:29.766 Timezonetest [10352:207] Pacific / Pitcairn

2011-09-28 09:50:29.767 Timezonetest [10352:207] Pacific / Pohnpei

2011-09-28 09:50:29.768 Timezonetest [10352:207] Pacific / Ponape

2011-09-28 09:50:29.769 Timezonetest [10352:207] Pacific / Port_Moresby

2011-09-28 09:50:29.773 Timezonetest [10352:207] Pacific / Rarotonga

2011-09-28 09:50:29.775 Timezonetest [10352:207] Pacific / Saipan

2011-09-28 09:50:29.775 Timezonetest [10352:207] Pacific / Tahiti

2011-09-28 09:50:29.776 Timezonetest [10352:207] Pacific / Tarawa

2011-09-28 09:50:29.776 Timezonetest [10352:207] Pacific / Tongatapu

2011-09-28 09:50:29.777 Timezonetest [10352:207] Pacific / Truk

2011-09-28 09:50:29.778 Timezonetest [10352:207] Pacific / Wake

2011-09-28 09:50:29.778 Timezonetest [10352:207] Pacific / Wallis

任何人都可以说上面列表中的CST(中央标准时区)的名称 在此先感谢

3 个答案:

答案 0 :(得分:3)

try this by first method u got all time zone after that wat u want u set by key value.

NSLog(@"%@",[NSTimeZone abbreviationDictionary]);

[dateFormater setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]];

答案 1 :(得分:1)

只需使用以下代码

即可
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]];

答案 2 :(得分:1)

试试这个:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
NSTimeZone *cst = [NSTimeZone timeZoneWithAbbreviation:@"GMT-06:00"];
[dateFormatter setTimeZone:cst];