Type MethodFoundationEssentials
verbatim(_:locale:timeZone:calendar:)
static func verbatim(_ format: Date.FormatString, locale: Locale? = nil, timeZone: TimeZone, calendar: Calendar) -> Date.VerbatimFormatStyle
Parameters
formatA
Date.FormatStringthat provides the explicit components and their respective styles to use when formatting a date.localeThe locale to use when formatting. Defaults to
nil.timeZoneThe time zone to use when formatting.
calendarThe calendar to use when formatting.
Return Value
A date format style that uses the provided format string and timekeeping parameters.
Discussion
Use this format style only when you need to produce or parse an exact format, such as when working with programmatically-produced date strings. For formatting dates that people read, use dateTime to get a localized Date.FormatStyle instead. To use the ISO-8601 standard, use FormatStyle/iso8601 to get a Date.ISO8601FormatStyle.
Use the dot-notation form of this type method when the call point allows the use of Date.VerbatimFormatStyle. You typically do this when calling the formatted(_:) method of Date.
The following example formats the current date with a verbatim format that uses a two-digit month, two-digit day, and default-digits year, separated by slashes. This style isn’t localized — it uses this format in any locale, ignoring locale-appropriate conventions.
let date = Date()
let formatted = date.formatted(
.verbatim("\(month: .twoDigits)/\(day: .twoDigits)/\(year: .defaultDigits)" as Date.FormatString,
locale: .autoupdatingCurrent,
timeZone: .current,
calendar: .current)) // 12/05/2022