【发布时间】:2018-02-28 07:08:32
【问题描述】:
我想将 dateStartString = “28/02/2018” 转换为 Date 并将转换后的日期与今天的日期进行比较。当我转换dateStartString 时,转换后的日期是"2018-02-27 18:30:00 UTC"。为什么它的输出是错误的日期?
这是我的代码
var dateStartString = "28/02/2018"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
guard let dateStartDate = dateFormatter.date(from: dateStartString) else {
fatalError("ERROR: Date conversion failed due to mismatched format.")
}
let dateToday = Date()
if(dateStartDate>=dateToday){
print("Yes")
}
else{
print("Today date is 28/02/2018. Why it print No?")
}
希望你能理解我的问题。 提前致谢。
【问题讨论】:
-
你在哪个时区?