1.对Date进行格式转化
let currentDate = Date()
print("当前时间:\(currentDate)")
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let stringDate = dateFormatter.string(from: currentDate)
print("转换后的当前时间:\(stringDate)")
2.对string样式日期进行转换
func toolsChangeDataStyle(toFullStyle string: String) -> String{
let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyyMMddHHmmss"
let date = dateFormat.date(from: string)
let dateMatt = DateFormatter()
dateMatt.dateFormat = "yyyy-MM-dd HH:mm:ss"
let str = dateMatt.string(from: date ?? Date())
return str
}