I know its simple but I cant just get it right. Have been staring at this long time. I have a string with 03AM but when I try to get date from it I cannot get it working. It gives me 1970-01-01 21:00:00 +0000. dont know why. Can anyone help out here :
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"ha"];
[dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease] ];
NSDate *date1 = [dateFormat dateFromString:display];
NSLog(@"Display 2开发者_Python百科 : %@", date1);
[dateFormat setDateFormat:@"ha"];
Should be:
[dateFormat setDateFormat:@"hh a"];
See if that works ;)
ref: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
To get AM/PM to display correctly you may have to set the locale to a special value. See this thread.
精彩评论