I'm using DateFormatter from Swift to show date to users in "yyyy.MM.dd" format. I find one thing very strange that even after I've set the Timezone, it gives me the date a day after.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy.MM.dd"
formatter.locale = Locale(identifier: "ko_kr")
formatter.timeZone = TimeZone(abbreviation: "KST")
let date = formatter.string(from: myDate)
myDate above is like 2023-06-29 18:25:13 +0000 For example, today is 2023.06.29 and it should return 2023.06.29 but it returns 2023.06.30.
Is there any other parts that I should look into?
You can set the defaultTimeZone property of the DateFormatter explicitly to the desired time zone (KST) using the TimeZone(abbreviation: "KST"). This ensures that the DateFormatter consistently uses the specified time zone when formatting the date, instead of relying on the device's default time zone.