Skip to content

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

fractional(_:)

Returns the numerical representation of the fractional component of the second. For example, 8, 827.

milliseconds(_:)

Returns the number of milliseconds elapsed in the day. For example, 11122827.

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

Type Methods

  • static func fractional(Int) -> Date.FormatStyle.Symbol.SecondFraction
    Fractional second (numeric). Truncates, like other numeric time fields, but in this case to the number of digits specified by the associated Int. For example, specifying 4 for seconds value 12.34567 yields 12.3456.
  • static func milliseconds(Int) -> Date.FormatStyle.Symbol.SecondFraction
    Milliseconds in day (numeric). The associated Int specifies 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.Equatable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype