One Logo Pool Ball
Foundation · IOS API REFERENCE

Date.FormatStyle.Symbol.Hour

struct · iOS 15.0+ · SDK 27.1

struct Hour

A type that specifies a format for the hour in a date format style. The type ``Date/FormatStyle/Symbol/Hour`` includes static factory variables and methods that create custom ``Date/FormatStyle/Symbol/Hour`` objects: |Factory variable|Description| |---|---| | ``defaultDigitsNoAMPM`` | The minimum number of digits that represents the full numeric hour. This doesn't include the day period (a.m. or p.m.). For example, `1`, `11`. | | ``twoDigitsNoAMPM`` | Two-digit numeric hour, zero-padded if necessary. This doesn't include the day period (a.m. or p.m.). For example, `01`, `11`. | | ``defaultDigits(amPM:)`` | The minimum number of digits that represents the full numeric hour. This may include the day period (a.m. or p.m.), depending on locale. For example, `7a` (`narrow`), `7AM` (`abbreviated`), `7A.M.` (`wide`). | | ``twoDigits(amPM:)`` | Two-digit numeric hour, zero-padded if necessary. This may include the day period (a.m. or p.m.), depending on locale. For example, `07a` (`narrow`), `07AM` (`abbreviated`), `07A.M.` (`wide`). | | ``conversationalDefaultDigits(amPM:)`` | The minimum number of digits that represents the full numeric hour. This may include the day period (a.m. or p.m.), depending on locale, and can include conversational period formats. For example, `7a` (`narrow`), `7AM` (`abbreviated`), `7A.M.` (`wide`). | | ``conversationalTwoDigits(amPM:)`` | Two-digit numeric hour, zero-padded if necessary. This may include the day period (a.m. or p.m.), depending on locale, and can include conversational period formats. For example, `07a` (`narrow`), `07AM` (`abbreviated`), `07A.M.` (`wide`). | To customize the hour format in a string representation of a `Date`, use ``Date/FormatStyle/hour(_:)`` The example below shows a variety of ``Date/FormatStyle/Symbol/Hour`` format styles applied to a date. ```swift let meetingDate = Date() // Feb 9, 2021 at 7:00 PM meetingDate.formatted(Date.FormatStyle().hour(.defaultDigitsNoAMPM)) // 7 meetingDate.formatted(Date.FormatStyle().hour(.twoDigitsNoAMPM)) // 07 meetingDate.formatted(Date.FormatStyle().hour(.defaultDigits(amPM: .narrow))) // 7p meetingDate.formatted(Date.FormatStyle().hour(.twoDigits(amPM: .abbreviated)) // 07 PM meetingDate.formatted(Date.FormatStyle().hour(.conversationalDefaultDigits(amPM: .wide)) // 7 P.M. ``` If no format is specified as a parameter, the ``Date/FormatStyle/Symbol/Minute/defaultDigits`` static variable is the default format. For more information about formatting dates, see the ``Date/FormatStyle``.

Members (7)

static · iOS 15.0+

defaultDigits

TypeScript
static defaultDigits(amPM: Date_FormatStyle_Symbol_Hour_AMPMStyle): Date_FormatStyle_Symbol_Hour
Swift declaration
static func defaultDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.Hour

The preferred numeric hour format for the locale with minimum digits. Whether the period symbol (AM/PM) will be shown depends on the locale.

get · iOS 15.0+

twoDigitsNoAMPM

TypeScript
static get twoDigitsNoAMPM(): Date_FormatStyle_Symbol_Hour
Swift declaration
static var twoDigitsNoAMPM: Date.FormatStyle.Symbol.Hour { get }

Custom format style portraying the numeric hour using two digits. This style pads the hour with a leading zero if necessary. It doesn't include the day period symbol (a.m. or p.m.). For example, `01`, `11`.

get · iOS 15.0+

defaultDigitsNoAMPM

TypeScript
static get defaultDigitsNoAMPM(): Date_FormatStyle_Symbol_Hour
Swift declaration
static var defaultDigitsNoAMPM: Date.FormatStyle.Symbol.Hour { get }

Custom format style portraying the minimum number of digits that represents the numeric hour. This style doesn't include the day period symbol (a.m. or p.m.). For example, `1`, `11`.

static · iOS 15.0+

conversationalTwoDigits

TypeScript
static conversationalTwoDigits(amPM: Date_FormatStyle_Symbol_Hour_AMPMStyle): Date_FormatStyle_Symbol_Hour
Swift declaration
static func conversationalTwoDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.Hour

Behaves like `twoDigits`: two-digit hour format for the locale, zero padded if necessary. May also use conversational period formats.

static · iOS 15.0+

conversationalDefaultDigits

TypeScript
static conversationalDefaultDigits(amPM: Date_FormatStyle_Symbol_Hour_AMPMStyle): Date_FormatStyle_Symbol_Hour
Swift declaration
static func conversationalDefaultDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.Hour

Behaves like `defaultDigits`: the preferred numeric hour format for the locale with minimum digits. May also use conversational period formats.

get · iOS 18.0+

omitted

TypeScript
static get omitted(): Date_FormatStyle_Symbol_Hour
Swift declaration
static let omitted: Date.FormatStyle.Symbol.Hour

The option for not including the symbol in the formatted output.

static · iOS 15.0+

twoDigits

TypeScript
static twoDigits(amPM: Date_FormatStyle_Symbol_Hour_AMPMStyle): Date_FormatStyle_Symbol_Hour
Swift declaration
static func twoDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.Hour

The preferred two-digit hour format for the locale, zero padded if necessary. Whether the period symbol (AM/PM) will be shown depends on the locale.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →