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
It seems that Atlantic/Azores does its DST change at midnight, and hence you’re likely hitting the issue discussed in Parsing Dates Without Times.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"