I have two dates. startDate
and endDate
which are one day apart. From the print function I get:
startDate
: 2023-01-01 05:07:33 +0000
endDate
: 2023-01-01 17:08:04 +0000
Of course this is UTC so the day is inaccurate but if I get the Calendar.Component
.day
for each date then I get 1
and 2
respectively which is what I expect.
I am trying to calculate the number of days between these two dates using:
Calendar.current.dateComponents([.day], from: startDate, to: endDate).day
However this is returning 0
. What am I don't wrong here? From what I understand since this function is using the Calendar
then it should ignore the UTC
format and return 1
.