Skip to content

Instance Property

presentation

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
Specifies the style to use when describing a relative date, such as “1 day ago” or “yesterday”.

Discussion

Express relative date formats in either numeric or named styles. For example:

if let past = Calendar.current.date(byAdding: .day, value: -7, to: Date()) {
    var formatStyle = Date.RelativeFormatStyle()

    formatStyle.presentation = .numeric
    past.formatted(formatStyle) // "1 week ago"

    formatStyle.presentation = .named
    past.formatted(formatStyle) // "last week"
}