Contents

SystemFormatStyle

A collection of format styles for displaying live-updating time information in Text views.

Declaration

enum SystemFormatStyle

Overview

Use the format styles in this namespace to present time-based data that automatically updates as the system clock advances. Each style formats a Date value into an AttributedString and conforms to both FormatStyle and DiscreteFormatStyle, allowing SwiftUI to efficiently schedule text updates at exactly the right moments.

You typically use these styles with the Text/init(_:format:)-2rl92 initializer:

let startDate = Date.now
let endDate = startDate.addingTimeInterval(300)

Text(.currentDate, format: .offset(to: startDate))
// Output: "3 minutes, 42 seconds"

Text(.currentDate, format: .stopwatch(startingAt: startDate))
// Output: "00:03.42"

Text(.currentDate, format: .timer(countingDownIn: startDate..<endDate))
// Output: "4:17"

Text(.currentDate, format: .reference(to: endDate))
// Output: "in 5 minutes"

Choosing a Style

Style

Purpose

Example Output

Dateoffset

Elapsed time since or until a date

3 minutes, 42 seconds

Stopwatch

Precision stopwatch counting up

00:03.42

Timer

Countdown or count-up within a bounded interval

4:17

Datereference

Natural-language reference to a date

in 5 minutes, yesterday

Topics

Structures

See Also

Formatting date and time