<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/RegexComponent/iso8601WithTimeZone(includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:timeZoneSeparator:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:17_StringProcessing14RegexComponentP10FoundationAD4DateV18ISO8601FormatStyleVRszrlE19iso8601WithTimeZone26includingFractionalSeconds13dateSeparator0qlR004timeR00smR0AHSb_AH0fR0OAH0flR0OAH0lR0OAH0lmR0OtFZ"
  },
  "title" : "iso8601WithTimeZone(includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:timeZoneSeparator:)"
}
-->

# iso8601WithTimeZone(includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:timeZoneSeparator:)

Creates a regex component that matches an ISO 8601-formatted date string that includes a time zone component, capturing the matched substring as a Foundation date.

```
static func iso8601WithTimeZone(includingFractionalSeconds: Bool = false, dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash, dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator = .standard, timeSeparator: Date.ISO8601FormatStyle.TimeSeparator = .colon, timeZoneSeparator: Date.ISO8601FormatStyle.TimeZoneSeparator = .omitted) -> Self
```

## Parameters

`includingFractionalSeconds`

A Boolean value that specifies whether the source string contains fractional seconds. The default is `false`.

`dateSeparator`

The character that separates year, month, and day sections of the date substring. The default is <doc://com.apple.documentation/documentation/Foundation/Date/ISO8601FormatStyle/DateSeparator-swift.enum/dash>.

`dateTimeSeparator`

The character that separates the date and time sections of the substring. The default is <doc://com.apple.documentation/documentation/Foundation/Date/ISO8601FormatStyle/DateTimeSeparator-swift.enum/standard>.

`timeSeparator`

The character that separates the date and time sections of the substring. The default is <doc://com.apple.documentation/documentation/Foundation/Date/ISO8601FormatStyle/TimeSeparator-swift.enum/colon>.

`timeZoneSeparator`

The character that separates the hour, minute, and second sections of the substring. The default is <doc://com.apple.documentation/documentation/Foundation/Date/ISO8601FormatStyle/TimeSeparator-swift.enum/colon>

## Return Value

A `RegexComponent` that matches ISO 8601-formatted date substrings as Foundation <doc://com.apple.documentation/documentation/Foundation/Date> instances.

## Discussion

This method matches an ISO 8601 date string using the provided separator characters.

The following example creates a [`Regex`](/documentation/Swift/Regex) that matches an ISO 8601-formatted date. The format looks for a dash for the date separator, the standard date/time separator (none), a colon for the time separator, and no separator for the time zone. It then matches this regex against a source string containing a date with this format (specifying a time zone five hours behind UTC), some whitespace, a substring, more whitespace, and a currency value.

```
let iso860Source = "2022-07-14T21:10:15-05:00   Lemon-lime slushie      $1.99"
let matcher = Regex {
    Capture {
        One(.iso8601WithTimeZone(includingFractionalSeconds: false,
                                 dateSeparator: .dash,
                                 dateTimeSeparator: .standard,
                                 timeSeparator: .colon,
                                 timeZoneSeparator: .omitted))
    }
    OneOrMore(.horizontalWhitespace)
    OneOrMore(.any)
    OneOrMore(.horizontalWhitespace)
    One(.localizedCurrency(code:Locale.Currency("USD"),
                           locale:Locale(identifier: "en_US")))
}
let match = iso860Source.firstMatch(of: matcher)
let date = match?.1 // date == Jul 14, 2022 at 7:10 PM (may vary depending on current locale)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)