UIViews
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)}
/>| Prop | Type | Description |
|---|---|---|
date | Date | Point in time to display. An invalid Date throws an error. |
style | DateTextStyle | System date style. See Date styles. |
prefix | string | Static text before the date. |
suffix | string | Static 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 value | Purpose | Updates automatically |
|---|---|---|
DateTextStyle.relative | Displays a duration such as โ5 minutes.โ | Yes |
DateTextStyle.offset | Displays a signed time offset. | Yes |
DateTextStyle.timer | Displays a countdown or elapsed time. | Yes |
DateTextStyle.date | Displays a fixed calendar date. | No |
DateTextStyle.time | Displays 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