yyyy-MM-dd HH:mm:ss
1 . HH 表示24小时制
2 . hh 表示12 小时制
DD 是错误的写法,会出现day解析异常 ,要小写
var startCompo : DateComponents { let startCompo = dateFormatter.calendar.dateComponents(yearSet, from: startDate ?? Date.init(timeIntervalSince1970: 0)) return startCompo }
var endCompo : DateComponents { let endCompo = dateFormatter.calendar.dateComponents(yearSet, from: endDate ?? Date.init()) return endCompo }
var dateFormatter: DateFormatter { let dateFormatter = DateFormatter.init() dateFormatter.dateFormat = formate return dateFormatter }
var formate = "yyyy-MM-dd HH:mm:ss"
let yearSet = Set(arrayLiteral: Calendar.Component.year,Calendar.Component.month,Calendar.Component.day,Calendar.Component.hour,Calendar.Component.minute,Calendar.Component.second)
var component: DateComponents { return dateFormatter.calendar.dateComponents(yearSet, from: startDate!, to: endDate!) }
网友评论