weekOfYear()
Modifies the ISO 8601 date format style to include the week of the year in the formatted output.
Declaration
func weekOfYear() -> Date.ISO8601FormatStyleReturn Value
An ISO 8601 date format style modified to include the week of the year.
Discussion
The following example shows an ISO 8601 format with, and without, a week of the year.
let meetingDate = Date() // Jun 23, 2021 at 12:51 PM
meetingDate.formatted(.iso8601
.year()
.month()
.weekOfYear()
) // 202106W25
meetingDate.formatted(.iso8601
.year()
.month()
.day()
.weekOfYear()
) // 202106W2504
meetingDate.formatted(.iso8601
.year()
.day()
.weekOfYear()
) // 2021W2504When the format style includes the week of year, the output represents the day as the ordinal day of the week.
The default Date.ISO8601FormatStyle includes the month.
For more information about formatting dates, see the Date.FormatStyle.