【发布时间】:2011-10-14 05:38:44
【问题描述】:
当我在 CoreData 中将日期存储为 [NSDate 日期] 时,它会保存 -5:30 的差异。在核心数据中,我使用属性类型作为日期。
如何用时区存储 NSdate?
更新:这是我正在使用的代码:
存储日期:
database = (DataBase*) [fetchResults objectAtIndex:indexVal];
[database setDate:[NSDate date]];
NSError error = nil;
[managedObjectContext save:&error]
要检索日期:
DataBase *newDataBase = (DataBase) [fetchResults objectAtIndex:i];
NSDate *RetrivedDate = [newDataBase Date];
NSLog(@"Retrived Date :",RetrivedDate");
在存储之前,我会记录它。它显示当前日期和时间。存储后我立即获取日期。但它显示了 1 天的延迟日期..
【问题讨论】: