问题描述
我有这样的时间..
var utcTime = "\(dic["Due_Date"]!)"
utcTime
显示"2020-08-23T18:49:15"
我将其拆分为不同的组件。
self.dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
self.dateFormatter.locale = Locale(identifier: "en_US")
self.dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
if let date = dateFormatter.date(from:utcTime) {
let monthInt = Calendar.current.component(.month,from: date) //Displays 8
let dayInt = Calendar.current.component(.day,from: date) //Displays 24 instead of 23
let yearInt = Calendar.current.component(.year,from: date) //Displays 2020
}
在这里,除了当天以外,我正在使用所有其他组件。 utcTime
显示"2020-08-23T18:49:15"
时,日期而不是显示23显示24。日期由上面的dayInt
给出。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)