conversion from NSTimeInterval to days

2.3k Views Asked by At

I have a date1 and the current Date when the view did load. Now I want to display how many days have passed since the day.

let timeInterval = date1.timeIntervalSince(date2)

Now I want to convert the timeInterval in days. Anyone could help?

1

There are 1 best solutions below

0
Joakim Danielson On

Rather than using TimeInterval you can get the number of days directly by using the Calendar class and DateComponents

let days = Calendar.current.dateComponents([.day], from: date1, to: date2)
print(days.day!)