<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Text/init(_:format:)-8sfgg",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4TextV_6formatAcA14TimeDataSourceVyxG_q_tc11FormatInputQy_Rsz10Foundation08DiscreteH5StyleR_SS0H6OutputRt_r0_lufc"
  },
  "title" : "init(_:format:)"
}
-->

# init(_:format:)

Creates a text view that displays the current system time as defined by the
given format style, keeping the text up to date as time progresses.

```
init<V, F>(_ source: TimeDataSource<V>, format: F) where V == F.FormatInput, F : DiscreteFormatStyle, F.FormatOutput == String
```

## Discussion

Use this initializer to create a text view that updates as time progresses, just
like `init(_:style:)`, but with the flexibility of Foundation’s `FormatStyle`
protocol.

In the following example, the first `Text` view presents the current date and
time, whereas the second view displays a soccer clock counting from `startDate`.
Both views are kept up to date as time progresses.

```
Text(.currentDate, format: .dateTime)
Text(.durationOffset(to: startDate), format: .time(pattern: .minuteSecond))
```

## Redaction for Reduced Luminance

When the text is displayed with reduced luminance and frame rate, it
automatically modifies the `format` or its output so it never shows outdated
information.

If the `format` is known to SwiftUI and allows removing units or fields, SwiftUI
removes parts that change more frequently than the frame rate allows. E.g. a
string like *13 minutes, 22 seconds* would change to just `13 minutes`.

Otherwise, all digits in the formatted output are redacted using dashes.

> Note: In a widget, this `Text` becomes horizontally flexible and
> expands to fill the available width, because its displayed content
> keeps updating over time. Widgets can’t perform layout again after
> the system archives them, so the text can’t measure itself against
> its eventual content without risking clipping. If you want to
> constrain the width, apply a
> ``View/frame(width:height:alignment:)`` modifier, and use
> ``View/multilineTextAlignment(_:)`` to align the text within
> that frame.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)