-2

my string value is "2021.09.28 23:39".

but converted date is Optional(2021-09-28 14:39:00 +0000)

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd HH:mm"
dateFormatter.locale = Locale(identifier: "ko_kr")
dateFormatter.timeZone = TimeZone(abbreviation: "KST")
let date = dateFormatter.date(from: "2021.09.28 23:39")
let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: date!)
Rob
  • 415,655
  • 72
  • 787
  • 1,044
71873
  • 13
  • 3
  • 2
    You are successfully converting the string to its date equivalent and getting the right answer, so what is your question? – matt Sep 28 '21 at 15:01

1 Answers1

1

This is working correctly.

The KST timezone is UTC +9.

So... a time of 23:39 in the time zone KST is the same moment in time as the time 14:39 in UTC.

You output of Optional(2021-09-28 14:39:00 +0000) shows the timezone of +0000 and so is a displayed as a UTC time.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306