Structure
Date.FormatStyle.Symbol.Hour
struct Hour
Overview
The type Date.FormatStyle.Symbol.Hour includes static factory variables and methods that create custom Date.FormatStyle.Symbol.Hour objects:
Factory variable |
Description |
|---|---|
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, |
|
Two-digit numeric hour, zero-padded if necessary. This doesn’t include the day period (a.m. or p.m.). For example, |
|
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, |
|
Two-digit numeric hour, zero-padded if necessary. This may include the day period (a.m. or p.m.), depending on locale. For example, |
|
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, |
|
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, |
To customize the hour format in a string representation of a Date, use hour(_:) The example below shows a variety of Date.FormatStyle.Symbol.Hour format styles applied to a date.
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 defaultDigits static variable is the default format.
For more information about formatting dates, see the Date.FormatStyle.
Topics
Structures
struct AMPMStyleThe format style of the string representation of the day period, before or after noon, in a date.
Type Properties
static var defaultDigitsNoAMPM: Date.FormatStyle.Symbol.HourCustom format style portraying the minimum number of digits that represents the numeric hour.static let omitted: Date.FormatStyle.Symbol.HourThe option for not including the symbol in the formatted output.static var twoDigitsNoAMPM: Date.FormatStyle.Symbol.HourCustom format style portraying the numeric hour using two digits.
Type Methods
static func conversationalDefaultDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.HourBehaves likedefaultDigits: the preferred numeric hour format for the locale with minimum digits. May also use conversational period formats.static func conversationalTwoDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.HourBehaves liketwoDigits: two-digit hour format for the locale, zero padded if necessary. May also use conversational period formats.static func defaultDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.HourThe preferred numeric hour format for the locale with minimum digits. Whether the period symbol (AM/PM) will be shown depends on the locale.static func twoDigits(amPM: Date.FormatStyle.Symbol.Hour.AMPMStyle) -> Date.FormatStyle.Symbol.HourThe 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.
Relationships
Conforms To
Swift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype