如何从 coreData 格式化 NSDate 并正确显示
我想格式化来自 coreData 的日期。 我使用这行代码从 coredata 获取日期:
[[managedObject valueForKey:@"presentationDate"] description]
我知道我可以使用 NSDateFormatter 格式化 NSDate。
这是我的代码:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MMM.yyyy"];
NSDate *date = (NSDate *)
[[managedObject valueForKey:@"presentationDate"] description];
NSLog(@"theDate: |%@| \n", [dateFormat stringFromDate:date]);//output is null
输出为空。我找不到正确的方法来正确显示日期。请帮忙。
i want to format my date which comes from coreData.
i am getting the date from coredata with this line of code:
[[managedObject valueForKey:@"presentationDate"] description]
i know that i can format the NSDate with NSDateFormatter.
here is my code:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MMM.yyyy"];
NSDate *date = (NSDate *)
[[managedObject valueForKey:@"presentationDate"] description];
NSLog(@"theDate: |%@| \n", [dateFormat stringFromDate:date]);//output is null
The output ist null. I cant find the right way to put out the date correctly. please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果presentationDate是一个DATE并且它的类是托管对象中的DATE,那么错误就在这里
你最好这样写
If presentationDate is a DATE and its class is DATE in the managed object, then the error is here
You'd better writing this
-description
方法总是返回描述对象的NSString
。因此,从核心数据获取对象时一定不要调用它。
-description
method always returnsNSString
that describes object.So, you mustn't call it when getting object from core data.