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

unitsStyle

The style to use when formatting the quantity or the name of the unit, such as “1 day ago” or “one day ago”. 単位の量または名前を書式設定する時に使う様式、たとえば “1 day ago” または “one day ago”。

Declaration 宣言

Discussion 議論

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

See Also 参照

Modifying a Relative Date Format Style