time(includingFractionalSeconds:)
Modifies the ISO 8601 date format style to include the time in the formatted output.
Declaration
func time(includingFractionalSeconds: Bool) -> Date.ISO8601FormatStyleParameters
- includingFractionalSeconds:
Specifies whether the format style inclues the fractional component of the seconds.
Return Value
An ISO 8601 date format style modified to include the time.
Discussion
The following example shows an ISO 8601 format with, and without, a time and fractional seconds.
let meetingDate = Date() // Jun 24, 2021 at 6:52 AM
meetingDate.formatted(.iso8601
.year()
.month()
.day()
.time(includingFractionalSeconds: false)
)
// 20210624T115209
meetingDate.formatted(.iso8601
.year()
.time(includingFractionalSeconds: true)
)
// 2021T115209.274
meetingDate.formatted(.iso8601
.year()
.year()
.month()
.day()
.dateSeparator(.dash)
.time(includingFractionalSeconds: true)
.timeSeparator(.colon)
)
// 2021-06-24T11:52:09.274
meetingDate.formatted(.iso8601
.year()
.year()
.month()
.day()
.dateSeparator(.dash)
.time(includingFractionalSeconds: false)
.timeSeparator(.colon)
.dateTimeSeparator(.space)
)
// 2021-06-24 11:52:09The default Date.ISO8601FormatStyle includes the time but not the fractional seconds.
For more information about formatting dates, see the Date.FormatStyle.