Type Alias

Date.IntervalFormatStyle.TimeStyle

The type that defines time styles that vary in length or in their included components. 長さにおいてまたはそれらの含有構成要素において一様ではない時刻スタイルそれらを定義する型。

Declaration 宣言

Discussion 議論

The exact format depends on the locale. Possible time styles include: omitted, shortened, standard, and complete. 正確な書式設定は、ロケールに依存します。可能な時刻スタイルは次を含みます:omittedshortenedstandard、そしてcomplete

The following code sample shows a variety of time style format results using the en_US locale. 以下のコード例は、様々な時刻スタイル書式設定結果をen_USロケールを使って示します。


if let today = Calendar.current.date(byAdding: .day, value: -120, to: Date()),
   let thirtyDaysBeforeToday = Calendar.current.date(byAdding: .day, value: -30, to: today) {
   // today: Apr 11, 2021 at 7:14 AM
   // thirtyDaysBeforeToday: Mar 12, 2021 at 7:14 AM


   // Create a Range<Date>.
   let last30days = thirtyDaysBeforeToday..<today
    
    last30days.formatted(date: .omitted, time: .standard)
// 3/12/2021, 7:11:16 AM – 4/11/2021, 7:11:16 AM


    last30days.formatted(date: .numeric, time: .omitted)
// 3/12/2021 – 4/11/2021


    last30days.formatted(date: .abbreviated, time: .omitted)
// Mar 12 – Apr 11, 2021


    last30days.formatted(date: .long, time: .omitted)
// March 12 – April 11, 2021"


    last30days.formatted(date: .complete, time: .omitted)
// Friday, March 12 – Sunday, April 11, 2021


    last30days.formatted()
// 3/12/21, 7:14 AM – 4/11/21, 7:14 AM
}

See Also 参照

Supporting Types 支援を行う型