DateFormatter correct TimeZone set but output is in a bad time zone

Hi, I'm trying to print out the time of a Date object but instead of printing "GMT+2" as it should, it prints "GMT+1" time. I am using the current time zone and locale.

I expect the time string to be 3:00:27 PM GMT+2 but instead it is 2:00:27 PM GMT+1.

Here is my playground and its output:

import Foundation

let dateStr = "2020-01-01T13:00:27Z"
let date = ISO8601DateFormatter().date(from: dateStr)!

let formatter = DateFormatter()
formatter.timeStyle = .long

print(formatter.timeZone.abbreviation()!)
print(formatter.string(from: date))
GMT+2
2:00:27 PM GMT+1

I got it: in jan 01. the time zone was CET and right now it is CEST, so DateFormatter was right.

4 Likes
Terms of Service

Privacy Policy

Cookie Policy