我试图将传递的NSDate转换为UILabel的可读日期/时间字符串。由于某些原因,标签在输出中显示了意外的日期。
struct myDateRange{
var startDate: NSNumber?
var endDate: NSNumber?
}
func configureDate(date:myDateRange){
let date = NSDate(timeIntervalSince1970: date.startDate as! TimeInterval)
let timeFormat = DateFormatter()
timeFormat.timeStyle = .short
timeFormat.dateStyle = .short
let currentTime = "\(timeFormat.string(from: date as Date))"
timeLabel.text = String(currentTime)
}
输出:
通过:可选(1518393600000)
labeltext:12/23/85,上午10:30
预期:
02/12/18, 12:00