<!--
{
  "documentType" : "article",
  "framework" : "WidgetKit",
  "identifier" : "/documentation/WidgetKit/Displaying-Dynamic-Dates",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Displaying dynamic dates in widgets"
}
-->

# Displaying dynamic dates in widgets

Show up-to-date, time-based information in your widget even when it
isn’t running.

## Overview

Because your widget extension isn’t always running, you can’t directly update
your widget’s content. Instead, WidgetKit renders your widget’s view on your
behalf and displays the result. However, some SwiftUI views let you display
content that continues updating while your widget is visible.

Using a <doc://com.apple.documentation/documentation/SwiftUI/Text> view in your
widget, you can display dates and times that stay up to date onscreen. The
following examples show the combinations available.

To display a relative time that updates automatically, use code similar to the example below:

```swift
let components = DateComponents(minute: 11, second: 14)
let futureDate = Calendar.current.date(byAdding: components, to: Date())!

Text(futureDate, style: .relative)
// Displays:
// 11 min, 14 sec

Text(futureDate, style: .offset)
// Displays:
// -11 minutes
```

Using the
<doc://com.apple.documentation/documentation/SwiftUI/Text/DateStyle/relative>
style shows the absolute difference between the current date and time and the
date specified, regardless of whether the date is in the future or the past.
The <doc://com.apple.documentation/documentation/SwiftUI/Text/DateStyle/offset>
style shows the difference between the current date and time and the date
specified, indicating dates in the future with a minus sign (`-`) prefix and dates in the
past with a plus sign (`+`) prefix.

To display a timer that continues updating automatically, use code similar to the example below:

```swift
let components = DateComponents(minute: 15)
let futureDate = Calendar.current.date(byAdding: components, to: Date())!

Text(futureDate, style: .timer)
// Displays:
// 15:00
```

For dates in the future, the
<doc://com.apple.documentation/documentation/SwiftUI/Text/DateStyle/timer>
style counts down until the current time reaches the specified date and time,
and counts up when the date passes.

To display an absolute date or time, use code similar to the example below:

```swift
// Absolute Date or Time
let components = DateComponents(year: 2020, month: 4, day: 1, hour: 9, minute: 41)
let aprilFirstDate = Calendar.current(components)!

Text(aprilFirstDate, style: .date)
Text("Date: \(aprilFirstDate, style: .date)")
Text("Time: \(aprilFirstDate, style: .time)")

// Displays:
// April 1, 2020
// Date: April 1, 2020
// Time: 9:41AM
```

To display a time interval between two dates, use code similar to the example below:

```swift
let startComponents = DateComponents(hour: 9, minute: 30)
let startDate = Calendar.current.date(from: startComponents)!

let endComponents = DateComponents(hour: 14, minute: 45)
let endDate = Calendar.current.date(from: endComponents)!

Text(startDate ... endDate)
Text("The meeting will take place: \(startDate ... endDate)")

// Displays:
// 9:30AM-2:45PM
// The meeting will take place: 9:30AM-2:45PM
```

To show progress toward a future date without reloading your widget, use <doc://com.apple.documentation/documentation/SwiftUI/ProgressView/init(timerInterval:countsDown:)>, as follows:

```swift
let start = Date.now
let end = start.addingTimeInterval(60 * 15)

ProgressView(timerInterval: start...end, countsDown: false)
```

The progress view fills in automatically as time passes from the start of the date range to the end. Set `countsDown` to `true` to leave the progress view empty instead.

To pair the progress view with a numeric countdown, or to show a countdown on its own without reloading your widget, use <doc://com.apple.documentation/documentation/SwiftUI/Text/init(timerInterval:pauseTime:countsDown:showsHours:)>, as shown here:

```swift
Text(timerInterval: start...end, countsDown: true)
// Displays:
// 15:00
```

Provide a `pauseTime` to stop the timer at a specific date, such as when a countdown reaches zero.

---

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)