DateFormatter return wrong year

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"

Answered by tkgka in 819454022

it was my bad

dateFormat need to be "yyyy-MM-dd"

Accepted Answer

it was my bad

dateFormat need to be "yyyy-MM-dd"

DateFormatter return wrong year
 
 
Q