<!--
{
  "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/date(_:locale:timeZone:calendar:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:17_StringProcessing14RegexComponentP10FoundationAD4DateV13ParseStrategyVRszrlE4date_6locale8timeZone8calendarAhF11FormatStyleV0fO0V_AD6LocaleVAD04TimeL0VAD8CalendarVSgtFZ"
  },
  "title" : "date(_:locale:timeZone:calendar:)"
}
-->

# date(_:locale:timeZone:calendar:)

Creates a regex component that matches a localized date string formatted in accordance with a style, capturing it as a Foundation date.

```
static func date(_ style: Date.FormatStyle.DateStyle, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil) -> Date.ParseStrategy
```

## Parameters

`style`

A <doc://com.apple.documentation/documentation/Foundation/Date/FormatStyle/DateStyle> to use when matching date substrings.

`locale`

The locale to use when matching date substrings. Matching uses this locale to evaluate the order of date components. It also uses the locale’s language for date format styles that use words.

`timeZone`

The time zone to use when returning a captured <doc://com.apple.documentation/documentation/Foundation/Date>. The returned date’s time value is `00:00:00` in this time zone.

`calendar`

The calendar to use when matching date substrings. If `nil`, matching uses the default calendar of the specified `locale`.

## Return Value

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

## Discussion

This method matches date substrings in accordance with the formatting of Foundation’s <doc://com.apple.documentation/documentation/Foundation/Date/FormatStyle>.

If a time value follows the date substring, the matcher ignores it, treating it as any other character sequence. To match date and time substrings, use [`dateTime(date:time:locale:timeZone:calendar:)`](/documentation/Swift/RegexComponent/dateTime(date:time:locale:timeZone:calendar:)).

The following example creates a [`Regex`](/documentation/Swift/Regex) that matches a date formatted with the <doc://com.apple.documentation/documentation/Foundation/Date/FormatStyle/DateStyle/numeric> style in the `en_US` locale. It then matches this regex against a source string containing a date with this format, some whitespace, a substring, more whitespace, and a currency value.

```
let source = "7/31/2022  Lemon-lime slushie      $1.99"
let matcher = Regex {
    Capture {
        One(.date(.numeric,
                  locale: Locale(identifier: "en_US"),
                  timeZone: TimeZone(identifier: "PST")!))
    }
}
guard let match = source.firstMatch(of: matcher) else { return }
let date = match.1 // date == Jul 31, 2022 at 12:00 AM PST
```

---

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)