Skip to content

Initializer

init(date:time:locale:calendar:timeZone:)

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
Creates a new FormatStyle with the given configurations.
init(date: Date.IntervalFormatStyle.DateStyle? = nil, time: Date.IntervalFormatStyle.TimeStyle? = nil, locale: Locale = .autoupdatingCurrent, calendar: Calendar = .autoupdatingCurrent, timeZone: TimeZone = .autoupdatingCurrent)

Parameters

date

The style for formatting the date part of the given date pairs. Note that if .omitted is specified, but the date interval spans more than one day, a locale-specific fallback will be used.

time

The style for formatting the time part of the given date pairs.

locale

The locale to use when formatting date and time values.

calendar

The calendar to use for date values.

timeZone

The time zone with which to specify date and time values.

Discussion

Important

Always specify the date length, time length, or the date components to be included in the formatted string with the symbol modifiers. Otherwise, an empty string will be returned when you use the instance to format an object.

Note

If specifying the date fields, and the DateInterval range is larger than the specified units, a locale-specific fallback will be used.

  • Example: for the range 2010-03-04 07:56 - 2010-03-08 16:11 (4 days, 8 hours, 15 minutes), specifying .hour().minute() will produce

    • for en_US, “3/4/2010 7:56 AM - 3/8/2010 4:11 PM”

    • for en_GB, “4/3/2010 7:56 - 8/3/2010 16:11”