my Date type data is "2024-12-28 15:00:00 +0000" and when I use Date formatter to format date with timezone TimeZone(identifier: "Asia/Seoul")
, date formatter return wrong year like below
(lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = TimeZone(identifier: "Asia/Seoul"); formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date) 2024-12-28 15:00:00 +0000 "2025-12-29"
(lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = .gmt; formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date) 2024-12-28 15:00:00 +0000 "2024-12-28"
dateFormat need to be yyyy-MM-dd
Yes.
In addition, if you’re parsing fixed-format dates then you’ll need to pin the locale to en_US_POSIX
. Without that you’ll see weird results for some with custom region settings. QA1480 NSDateFormatter and Internet Dates goes into this in some detail.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"