Apple has a whole page on how to display dynamic Date
s.
The WWDC20 widgets code-along example updates by the second. Their timeline entires are every minute.
Using a 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:
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
For dates in the future, the 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:
// 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)")