Skip to content

StructureFoundationEssentials

Date.ISO8601FormatStyle

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
A type that converts between dates and their ISO-8601 string representations.
struct ISO8601FormatStyle

Overview

The Date.ISO8601FormatStyle type generates and parses string representations of dates following the ISO-8601 standard, like 2024-04-01T12:34:56.789Z. Use this type to create ISO-8601 representations of dates and create dates from text strings in ISO 8601 format. For other formatting conventions, like human-readable, localized date formats, use Date.FormatStyle.

Instance modifier methods applied to an ISO-8601 format style customize the formatted output, as the following example illustrates.

let now = Date()
print(now.formatted(Date.ISO8601FormatStyle().dateSeparator(.dash)))
// 2021-06-21T211015Z

Use the static factory property FormatStyle/iso8601 to create an instance of Date.ISO8601FormatStyle. Then apply instance modifier methods to customize the format, as in the example below.

let meetNow = Date()
let formatted = meetNow.formatted(.iso8601
.year()
.month()
.day()
.timeZone(separator: .omitted)
.time(includingFractionalSeconds: true)
.timeSeparator(.colon)
) // "2022-06-10T12:34:56.789Z"

Topics

Operators

Initializers

Instance Properties

Instance Methods

Enumerations

  • enum DateSeparator
    A type describing the character separating year, month, and day components of a date in an ISO 8601 date format.
  • enum DateTimeSeparator
    Type describing the character separating the date and time components of a date in an ISO 8601 date format.
  • enum TimeSeparator
    Type describing the character separating the time components of a date in an ISO 8601 date format.
  • enum TimeZoneSeparator
    A type describing the character separating the time and time zone of a date in an ISO 8601 date format.

Default Implementations

Relationships

Conforms To

  • FormatStyle
  • ParseStrategy
  • ParseableFormatStyle
  • Swift.Copyable
  • Swift.Decodable
  • Swift.Encodable
  • Swift.Equatable
  • Swift.Escapable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype
  • _StringProcessing.CustomConsumingRegexComponent
  • _StringProcessing.RegexComponent