如何在 tableViewCell 中显示数据,我从核心数据中获取数据作为日期?这是我的代码,但它不起作用
let formatter = DateFormatter()
// initially set the format based on your datepicker date
formatter.dateFormat = "yyyy/MM/dd HH:mm:ss"
let myString = formatter.string(from: game.date! as Date)
// convert your string to date
print("str - \(myString)")
let yourDate = formatter.date(from: myString)
print("date - \(String(describing: yourDate!))")
//then again set the date format whhich type of output you need
formatter.dateFormat = "dd/MMM/yyyy HH:mm:ss"
// again convert your date to string
let myStringDate = formatter.string(from: yourDate!)
cell.detailTextLabel?.text = myStringDate
Date is fetching 这是一个输出
str - 2017/07/19 13:26:40
日期 - 2017-07-19 10:26:40 +0000
一个错误是
致命错误:在展开可选值 (lldb) 时意外发现 nil