Contents

Date.FormatStyle.Symbol.SecondFraction

A type that specifies the format for the second fraction in a date format style.

Declaration

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

Modifying a Second Fraction

Comparing Second Fractions

Type Properties

See Also

Modifying Date Style Format Symbols