So I have a date like this:
let date = Date()
Lets say that the date is 12.08.2021 14:40. I want to check and do stuff if there is more then 25 minutes past that date. How can I do this?
So I have a date like this:
let date = Date()
Lets say that the date is 12.08.2021 14:40. I want to check and do stuff if there is more then 25 minutes past that date. How can I do this?
3
Answers
You can use
timeIntervalSinceNow
and measure the difference (in seconds)This example is relative, so will always print
"not past 25 minutes"
– howeverpreviousDate
would be the actual previous date.The below function will allow you to check if the elapsed time since a previous date is more than a specific number of minutes.
Note: This method only works with iOS 13 and above.
I made this function. you use
date.timeAgoSince()
. This confirms how many minutes ago your variable was.