When using DateFormatter with the Atlantic/Azores timezone, calling date(from: formattedString) for the date 2026-03-29 returns nil unexpectedly.
codes:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd" // 年月日格式
dateFormatter.timeZone = TimeZone(identifier: "Atlantic/Azores")
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
var now = Date()
now -= 60 * 60 * 13
let formattedString = dateFormatter.string(from: now)
let dateWithTimeZone = dateFormatter.date(from: formattedString)
print(formattedString) //20260329
print(dateWithTimeZone) // nil
Topic:
Programming Languages
SubTopic:
Swift
0
0
30