I tried something like this:
var calendar = Calendar.current
var dayFutureComponents = DateComponents()
dayFutureComponents.day = 1 // aka 1 day
var d = calendar.date(byAdding: dayFutureComponents, to: Date())
...//setting of d.hour, d.minute, d.second to zero and finding the difference between 2 dates
The problem is for example my current GMT is +3
. So the result differs from one I need to achieve by 3 hours. How to fix this issue?
Missed out that when I for example set hour to 0 - it displayed according to GMT (in my case it is 3 hours of difference). And When I calculate the difference between 2 dates - both dates has the same "displacement" so final result should be the same
First create a
Calendar
for the UTC timezone. Second get thestartOfDay using the UTC calendar. Third add one day to that date. Then you can use
Datemethod
timeIntervalSince(_ Date)` to calculate the amount of seconds between those two dates:Playground Testing: