Один из способов сделать это, чтобы расширить класс Date
вернуть разницу - и, хотя вы только показать минуты , вы должны быть в состоянии обрабатывать интервалы как «3-х дней, 2 часов, 23 минут» - конечно же, вы можете выбрать для отображения, что как только «3 дня», или «более 51 часов»
extension Date
{
func differenceInDays(date: Date) -> Int
{
return Calendar.current.dateComponents([.day], from: self, to: date).day!
}
func differenceInHours(date: Date) -> Int
{
// returns the TOTAL number of hours, not just the hour component
return Calendar.current.dateComponents([.hour], from: self, to: date).hour!
}
func differenceInMinutes(date: Date) -> Int
{
// returns the TOTAL number of minutes, not just the minute component
return Calendar.current.dateComponents([.minute], from: self, to: date).minute!
}
}
Do у вас есть базовый объект 'Date'? Если это так, используйте 'DateIntervalFormatter'. –