-(NSString *)dateFormat:(NSString *)str{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy/mm/dd HH:mm:ss zzz"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:str];
//problem here when i call this method from simulator and ipod it runs perfectly
//and returns 2015-01-27 00:27:48 +0000 but in case of IPad(iOS 8.3) it return NIL
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterMediumStyle];
[df setTimeStyle:NSDateFormatterShortStyle];
NSString* myString = [df stringFromDate:dateFromString];
return myString;
}
//code to call above method with date string which are return from web service
[self dateFormat:@"2015/01/26 16:27:48 PST"];
答案 0 :(得分:1)
检查输入字符串日期格式。
它应采用以下格式: - yyyy/MM/dd HH:mm:ss zzz
答案 1 :(得分:1)
您应该检查ipad日期和时间设置。要将字符串,2015/01/26 16:27:48转换为日期,ipad日期和时间格式必须为24小时。
答案 2 :(得分:0)
月份由'MM'表示,而不是'mm'。将日期格式更改为
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss zzz"];