Instance Property インスタンスプロパティ

presentation

Specifies the style to use when describing a relative date, such as “1 day ago” or “yesterday”.

Declaration 宣言

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"
}

See Also 参照

Modifying a Relative Date Format Style