我怎样才能让单元格显示它的创建和编辑时间?
我找不到关于这个的任何信息
分钟/小时/天/周等
代码部分:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
cell.nameText?.text = myData[indexPath.row]
//
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy HH:mm:ss"
let stringDate = formatter.string(from: date)
//
cell.NoneLabel?.text = stringDate
return cell
}
最佳答案
您可以在cellForRowAt
方法中获取Date()
。
此 Date()
将为您提供创建单元格时的当前日期时间。
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy HH:mm"
let stringDate = formatter.string(from: date)
您可以随意更改格式。
然后你可以计算单元格创建的时间。 要计算,请检查此 link .
关于ios - 在表中显示单元格创建时间 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48645085/