NSDateFormatter 在 ios 4.3.3 中为日期返回 null
我正在将字符串转换为日期,然后再次转换为字符串。使用以下代码
NSString *newDate =[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Date]];
NSLog(@"New Date is %@",newDate);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy h:mm:ss a"];
NSDate *myDate = [dateFormat dateFromString:newDate];
[dateFormat setDateFormat:@"MM/dd/yyyy"];
NSString *str = [dateFormat stringFromDate:myDate];
NSLog(@"DAte is %@",str);
它在模拟器中返回日期,但在 iphone 4.3.3 中则不然 请帮忙
I am converting string to date and again to string. using following code
NSString *newDate =[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Date]];
NSLog(@"New Date is %@",newDate);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy h:mm:ss a"];
NSDate *myDate = [dateFormat dateFromString:newDate];
[dateFormat setDateFormat:@"MM/dd/yyyy"];
NSString *str = [dateFormat stringFromDate:myDate];
NSLog(@"DAte is %@",str);
It is returning date in simulator but not in iphone 4.3.3
please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果无法从字符串中获取日期,
NSDateFormatter
将返回 nil。要查看它是否可以解析日期,请添加另一个 NSLog 语句:
但是既然您只想要字符串的第一部分,为什么不直接将其子字符串化。
这里返回什么:
它的属性 Date 已经是 NSDate ?,你能显示你的 Jobs .h 文件吗?
NSDateFormatter
will return nil if it can't get the date from a string.To see if it can parse the date add an other NSLog statement:
But since you only want the firs part of the string why not just substring it.
and what is returned here:
it the property Date already a NSDate ?, can you show your .h file for Jobs?