CoreData 使用的默认 NSTimeInterval
Default NSTimeInterval used by CoreData
NSDate
值由 CloudKit
返回。当我将日期存储在核心数据中时,系统会选择哪种表示形式 NSTimeInterval
?我知道 NSTimeInterval
存储自某个特定参考日期以来的秒数。但是这里会选择哪个参考日期呢?
mo.setValue(record.creationDate, forKey: "creationDate")
稍后我必须将此日期与当前日期进行比较,因此我必须将其转换回 NSDate
,因此我必须使用 NSDate timeIntervalSinceXXX
方法之一。
我在 docs 中找到了这个:
Dates and Times
NSManagedObject represents date attributes using NSDate objects, and stores times internally as an NSTimeInterval value since the reference date (which has a time zone of GMT). Time zones are not explicitly stored—indeed you should always represent a Core Data date attribute in GMT, this way searches are normalized in the database. If you need to preserve the time zone information, you need to store a time zone attribute in your model. This may again require you to create a subclass of NSManagedObject.
我不说什么是参考
如文档和注释中所述,内部 NSDate
参考日期是 2001 年 1 月 1 日,这是 Core Data 在将 NSDate
对象序列化为数据库表示时内部使用的日期。
参见 Wikipedia's article on epoch. NSDate
and CFDate
both use the Cocoa epoch time (which dates at least to 1994, in the OpenStep specifications)。
NSDate
值由 CloudKit
返回。当我将日期存储在核心数据中时,系统会选择哪种表示形式 NSTimeInterval
?我知道 NSTimeInterval
存储自某个特定参考日期以来的秒数。但是这里会选择哪个参考日期呢?
mo.setValue(record.creationDate, forKey: "creationDate")
稍后我必须将此日期与当前日期进行比较,因此我必须将其转换回 NSDate
,因此我必须使用 NSDate timeIntervalSinceXXX
方法之一。
我在 docs 中找到了这个:
Dates and Times NSManagedObject represents date attributes using NSDate objects, and stores times internally as an NSTimeInterval value since the reference date (which has a time zone of GMT). Time zones are not explicitly stored—indeed you should always represent a Core Data date attribute in GMT, this way searches are normalized in the database. If you need to preserve the time zone information, you need to store a time zone attribute in your model. This may again require you to create a subclass of NSManagedObject.
我不说什么是参考
如文档和注释中所述,内部 NSDate
参考日期是 2001 年 1 月 1 日,这是 Core Data 在将 NSDate
对象序列化为数据库表示时内部使用的日期。
参见 Wikipedia's article on epoch. NSDate
and CFDate
both use the Cocoa epoch time (which dates at least to 1994, in the OpenStep specifications)。