OneScript

DateText

Display a date with native system formatting.

Display a JavaScript Date using SwiftUI's native date styles on Apple platforms.

import { Color, DateText, DateTextStyle, Modifier } from "onescript/views"

<DateText
  date={lastUpdatedAt}
  style={DateTextStyle.relative}
  prefix="Updated "
  suffix=" ago"
  modifier={Modifier.foregroundStyle(Color.secondary)}
/>
PropTypeDescription
dateDatePoint in time to display. An invalid Date throws an error.
styleDateTextStyleSystem date style. See Date styles.
prefixstringStatic text before the date.
suffixstringStatic text after the date.
Also accepts Modifiers, including font, fontWeight, foregroundStyle, and italic. prefix, the dynamic date, and suffix form one text view and share the same styling and wrapping behavior.

Date styles

Enum valuePurposeUpdates automatically
DateTextStyle.relativeDisplays a duration such as โ€œ5 minutes.โ€Yes
DateTextStyle.offsetDisplays a signed time offset.Yes
DateTextStyle.timerDisplays a countdown or elapsed time.Yes
DateTextStyle.dateDisplays a fixed calendar date.No
DateTextStyle.timeDisplays a fixed clock time.No

The system controls formatting, units, and localization. DateTextStyle.time formats the fixed point in time you pass; a live clock requires updates scheduled through the Widget Timeline.

How is this guide?

Last updated on

On this page