I want to get a today date without a time, so I can use it to compare with other Date objects that I am getting from API.
Here is my code:
var today = Date()
let gregorian = Calendar(identifier: .gregorian)
var components = gregorian.dateComponents([.timeZone, .year, .month, .day, .hour, .minute,.second], from: today)
components.hour = 0
components.minute = 0
components.second = 0
today = gregorian.date(from: components)!
But I have a strange problem with timezones. Today is for example 16/09/17, but at the end today would be equal to
2017-09-15 23:00:00 UTC
The only way to fix it is actually to specify my time zone as GMT.
components.timeZone = NSTimeZone(name: "GMT")! as TimeZone
Then the result would be correct one.
2017-09-16 00:00:00 UTC
Why you need to specify the timezone, as it is already should be set up by dateComponents or what I am doing wrong.
Before setting my own timezone it is equal to NSTimeZone "Europe/London"