unitsStyle
The style to use when formatting the quantity or the name of the unit, such as “1 day ago” or “one day ago”.
Declaration
var unitsStyle: Date.RelativeFormatStyle.UnitsStyleDiscussion
Express relative date format units in either wide, narrow, abbreviated, or spellOut styles. For example:
if let past = Calendar.current.date(byAdding: .day, value: -14, to: Date()) {
past.formatted(.relative(presentation: .named, unitsStyle: .wide)) // "2 weeks ago"
past.formatted(.relative(presentation: .named, unitsStyle: .narrow)) // "2 wk. ago"
past.formatted(.relative(presentation: .named, unitsStyle: .abbreviated)) // "2 wk. ago"
past.formatted(.relative(presentation: .named, unitsStyle: .spellOut)) // "two weeks ago"
}