Customize the date interval format style using modifier syntax to apply specific date and time formats, as in the following example:
日付間隔書式設定スタイルを修飾子構文を使ってカスタマイズすることで、特定の日付と時刻書式設定を適用してください、以下の例でのように:
let today =Date.nowiflet sevenDaysBeforeToday =Calendar.current.date(byAdding: .day, value: -7, to: today) {// Create a Range<Date>.let weekBefore = sevenDaysBeforeToday..<todaylet localeArray = ["en_US", "sv_SE", "en_GB", "th_TH", "fr_BE"]for localeID in localeArray {// Call the .formatted method on a Range<Date> and pass in an instance of Date.IntervalFormatStyle.print(weekBefore.formatted(.interval .day() .month(.wide) .weekday(.short) .hour(.conversationalTwoDigits(amPM: .wide)) .locale(Locale(identifier: localeID)))) }}// We, February 3, 3 PM – We, February 10, 3 PM// on 3 februari 15 – on 10 februari 15// We 3 February, 15 – We 10 February, 15// พ. 3 กุมภาพันธ์ 15 – พ. 10 กุมภาพันธ์ 15// me 3 février, 15 h – me 10 février, 15 h
The default format styles are numeric date format and shortened time format, as in the following example:
省略時の書式設定スタイルは、numeric日付書式設定とshortened時刻書式設定です、以下の例でのように:
let today =Date.nowiflet sevenDaysBeforeToday =Calendar.current.date(byAdding: .day, value: -7, to: today) {// Create a Range<Date>.let weekBefore = sevenDaysBeforeToday..<todayprint(weekBefore.formatted(.interval))}// 2/25/21, 12:58 PM – 3/4/21, 12:58 PM
See Also
参照
Creating a Date Interval Format Style
日付間隔書式設定スタイルを作成する
Creates an instance using the provided date, time, locale, calendar, time zone, and capitalization context.
あるインスタンスをこの提供された日付、時刻、ロケール、カレンダー、タイムゾーン、そしてキャピタライズ文脈を使って作成します。