'Can I make RelativeDateTimeFormatter display more units such year, month and day?

Here's my code:

let startDate = Calendar.current.date(from: DateComponents(year: 2022, month: 5, day: 1)) ?? .now
let endDate = Calendar.current.date(from: DateComponents(year: 2020, month: 6, day: 2)) ?? .now

let dateComponents = Calendar.current.dateComponents([.year, .month, .day], from: startDate, to: endDate)
let relativeDateTimeFormatter = RelativeDateTimeFormatter()
let dateRemainingText = relativeDateTimeFormatter.localizedString(from: dateComponents)

dateRemainingText is 1 year ago, while I would like it to be 1 year, 11 months, 1 day ago, which is more accurate

Can I make RelativeDateTimeFormatter display more units such year, month and day, so that it returns 1 year, 11 months, 1 day ago instead of 1 year ago?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source