来自NSString的NSDate

jam*_*one 6 iphone objective-c nsdate nsdateformatter

我已经阅读了DateFormatting指南,但我仍然无法获得有效的格式化程序.

NSString *string = @"0901Z 12/17/09";   
//This is a sample date. The Z stands for GMT timezone
//The 0901 is 09h 01m on a 24 hour clock not 12.
//As long as I can get the hours/min & date from the string I can deal with the time zone later
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"hhmm'Z' MM/dd/yy"];
NSDate *date = [dateFormat dateFromString:string];
Run Code Online (Sandbox Code Playgroud)

Car*_*rum 7

当我尝试它时,这对我有用.添加NSLog(@"%@", date)到代码的末尾给我这个输出:

2010-02-28 12:17:22.921 app[9204:a0f] 2009-12-17 09:01:00 -0800
Run Code Online (Sandbox Code Playgroud)

你看到的问题是什么?

编辑:我想通了,你没有遇到问题09:01,但是其他24小时都有问题14:25,对吧?将格式化程序更改为:

@"HHmm'Z' MM/dd/yy"
Run Code Online (Sandbox Code Playgroud)