📜  将日期保存到 userdefaults swift 代码示例

📅  最后修改于: 2022-03-11 15:01:03.848000             🧑  作者: Mango

代码示例1
//save as Date
UserDefaults.standard.set(Date(), forKey: key)

//read
let date = UserDefaults.standard.object(forKey: key) as! Date
let df = DateFormatter()
df.dateFormat = "dd/MM/yyyy HH:mm"
print(df.string(from: date))