Friday, May 1, 2026
HomeiOS Developmentios - dateComponents() from... to in days reveals from now to tomorrow...

ios – dateComponents() from… to in days reveals from now to tomorrow as 0 days?

[ad_1]

I’ve datecomponent objects that symbolize a while sooner or later. I need to calculate what number of dates from now till that date. I am additionally together with illustration of the dates merely as dates. What I am discovering is that when I’m making an attempt to point out what number of there are to a date that’s ‘tomorrow’ it is displaying 0. To my thoughts it must be displaying 1. I can attempt a hacky means of simply including 1 to my depend however I am questioning is it as a result of it is making an attempt to spherical to the closest 24 hours or one thing? In that case how can I ‘repair’ it?

Right here is my pattern code:

let nextDate = Date(timeInterval: Double(86400 * (myDurationInDaysAsInt)), since: myPreviousRelevantDate!)

let daysToNextDate = Calendar.present.dateComponents([.day], from: Date(), to: nextDate).day!

What I would wish to keep away from is the variety of days to the goal date altering through the day additionally – i.e. whatever the timestamp of my goal date – the variety of days to that day remaining fixed till midnight is reached.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments