📜  快速搅拌到日期 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:57.739000             🧑  作者: Mango

代码示例1
let isoDate = "2016-04-14T10:44:00+0000"

let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.date(from:isoDate)!

let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day, .hour], from: date)

let finalDate = calendar.date(from:components)