date(_:locale:timeZone:calendar:)
Creates a regex component to match a localized date string and capture the string as a Date
. The string is expected to follow the format of what Date.FormatStyle(date:locale:calendar:)
produces. Date
created by this regex component would be at 00:00:00 in the specified time zone.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
static func date(_ style: Date.FormatStyle.DateStyle, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil) -> Date.ParseStrategy
Parameters
- style
The style that describes the date string. For example,
.numeric
matches “10/21/2015”, and.abbreviated
matches “Oct 21, 2015” as October 21, 2015 in theen_US
locale..omitted
is invalid.- locale
The locale of the string to be matched. Generally speaking, the language of the locale is used to parse the date parts if the string contains localized numbers or words, and the region of the locale specifies the order of the date parts. For example, “3/5/2015” represents March 5th, 2015 in
en_US
, but represents May 3rd, 2015 inen_GB
.- timeZone
The time zone to create the matched date with. For example, parsing “Oct 21, 2015” with the PDT time zone returns a date representing October 21, 2015 at 00:00:00 PDT.
- calendar
The calendar with which to interpret the date string. If nil, the default calendar of the specified
locale
is used.
Returns
A RegexComponent
to match a localized date string.