weekday(_:)
Modifies the date interval format style to include the specified weekday style.
Declaration
func weekday(_ format: Date.IntervalFormatStyle.Symbol.Weekday = .abbreviated) -> Date.IntervalFormatStyleParameters
- format:
The weekday format style to apply to the date interval format style.
Return Value
A date interval format style that includes the specified weekday style.
Discussion
Use a combination of modifier instance methods to customize the format of the date interval. The following example shows a combination date interval format styles that include the weekday:
if let today = Calendar.current.date(byAdding: .day, value: -140, to: Date()),
let sevenDaysBeforeToday = Calendar.current.date(byAdding: .day, value: -7, to: today) {
// Create a Range<Date>.
let weekBefore = sevenDaysBeforeToday..<today
print(weekBefore.formatted(.interval.day().month(.wide).year().weekday(.wide)))
print(weekBefore.formatted(.interval.day().weekday(.abbreviated)))
print(weekBefore.formatted(.interval.day().month(.wide).weekday(.narrow)))
}
// Friday, February 5 – Friday, February 12, 2021
// 5 Fri – 12 Fri
// F, February 5 – F, February 12