将日期选择器中的日期保存到核心数据中
save date from date picker into core data
我在 macOS 上使用 swift 3,我想将我的日期选择器值保存在核心数据中。
我的实体中有一个属性(日期类型)。
我尝试使用此代码将我的日期选择器值保存到核心日期中:
let entity = NSEntityDescription.entity(forEntityName: "Person", in: context)
let newRecord = NSManagedObject(entity: entity!, insertInto: context) as! Person
newRecord.bday = myDatePicker.dateValue as NSDate
这个值将保存在 CoreData 中:
517935600
这是正确的吗? oO
可能吧。这取决于您在日期选择器中选择的日期。 NSDate
和 Date
将日期存储为自参考日期(UTC 2000 年 1 月 1 日开始)以来的秒数。您的日期选择器中的 UTC 值似乎是 2017 年 5 月 31 日 9:00 UTC。
我在 macOS 上使用 swift 3,我想将我的日期选择器值保存在核心数据中。
我的实体中有一个属性(日期类型)。 我尝试使用此代码将我的日期选择器值保存到核心日期中:
let entity = NSEntityDescription.entity(forEntityName: "Person", in: context)
let newRecord = NSManagedObject(entity: entity!, insertInto: context) as! Person
newRecord.bday = myDatePicker.dateValue as NSDate
这个值将保存在 CoreData 中: 517935600
这是正确的吗? oO
可能吧。这取决于您在日期选择器中选择的日期。 NSDate
和 Date
将日期存储为自参考日期(UTC 2000 年 1 月 1 日开始)以来的秒数。您的日期选择器中的 UTC 值似乎是 2017 年 5 月 31 日 9:00 UTC。