Docs
Text

Relative TimeNew

A timestamp that keeps itself current, rolling from just now to Yesterday only when its wording changes; tap for the exact time.

$npx swiftpieces add RelativeTime
Free · MIT + Commons ClauseiOS 17.0+timedaterelativetimestampfeedlocaleaccessibility
Type
RelativeTime
Files
RelativeTime.swift
Depends on
Nothing (Apple frameworks only)
Version
1.0.0

Colors and type for RelativeTime. .standard is the house palette.

Notes

  • Shows "just now" under a minute, then the locale's own wording from RelativeDateTimeFormatter, such as "1 min. ago", "3 hr. ago" or "Yesterday".
  • It sleeps until the wording would next change, the next whole minute, hour or day, and then rolls up to the new text. Nothing runs in between, so a long feed of them costs nothing.
  • Tap it to see the exact date and time in red, and tap again to go back. Turn this off with tapToReveal: false.
  • VoiceOver reads the full wording, such as "1 minute ago", and hints that a tap shows the exact time.
  • Under Reduce Motion the text changes with a fade instead of rolling.

Usage

RelativeTimeExample()

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add RelativeTime

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Relative Time" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All text →

Build it yourself: SwiftUI animations guide · Liquid Glass guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

Explore Pro