Skip to content

Type Method_StringProcessing

date(format:locale:timeZone:calendar:twoDigitStartDate:)

iOS 16.0+ iPadOS 16.0+ Mac Catalyst 16.0+ macOS 13.0+ tvOS 16.0+ watchOS 9.0+
Creates a regex component to match a localized date string following the specified format and capture the string as a Date.
static func date(format: Date.FormatString, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil, twoDigitStartDate: Date = Date(timeIntervalSince1970: 0)) -> Self

Parameters

format

The date format that describes the localized date string. For example, "\(month: .twoDigits)_\(day: .twoDigits)_\(year: .twoDigits)" matches “05_04_22” as May 4th, 2022 in the Gregorian calendar.

locale

The locale of the date string to be matched.

timeZone

The time zone to create the matched date with.

calendar

The calendar with which to interpret the date string. If nil, the default calendar of the specified locale is used.

Return Value

A RegexComponent to match a localized date string.