Structure
Date.FormatStyle.Symbol.SecondFraction
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
A type that specifies the format for the second fraction in a date format style.
struct SecondFraction
Overview
The type Date.FormatStyle.Symbol.SecondFraction includes static factory methods that create custom Date.FormatStyle.Symbol.SecondFraction objects:
Factory variable |
Description |
|---|---|
Returns the numerical representation of the fractional component of the second. For example, |
|
Returns the number of milliseconds elapsed in the day. For example, |
To customize the second format in a string representation of a Date, use secondFraction(_:). The following example shows a variety of Date.FormatStyle.Symbol.SecondFraction format styles applied to a date.
let meetingDate = Date() // Feb 9, 2021 at 3:05:41 PM
meetingDate.formatted(Date.FormatStyle().secondFraction(.fractional(3))) // 827
meetingDate.formatted(Date.FormatStyle().secondFraction(.fractional(1))) // 8
meetingDate.formatted(Date.FormatStyle().secondFraction(.milliseconds(4))) // 11122827
For more information about formatting dates, see the Date.FormatStyle.
Topics
Type Properties
static let omitted: Date.FormatStyle.Symbol.SecondFractionThe option for not including the symbol in the formatted output.
Type Methods
static func fractional(Int) -> Date.FormatStyle.Symbol.SecondFractionFractional second (numeric). Truncates, like other numeric time fields, but in this case to the number of digits specified by the associatedInt. For example, specifying4for seconds value12.34567yields12.3456.static func milliseconds(Int) -> Date.FormatStyle.Symbol.SecondFractionMilliseconds in day (numeric). The associatedIntspecifies the minimum number of digits, with zero-padding as necessary. The maximum number of digits is 9. This field behaves exactly like a composite of all time-related fields, not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This reflects the fact that is must be combined with the offset field to obtain a unique local time value.
Relationships
Conforms To
Swift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype