toRelativeTime

fun Long.toRelativeTime(now: Instant = Clock.System.now()): String(source)

Returns a human-readable relative time string from an epoch-second timestamp compared to now (defaults to the current instant).

Examples:

  • 30 seconds ago → "just now"

  • 5 minutes ago → "5 minutes ago"

  • 2 hours ago → "2 hours ago"

  • 3 days ago → "3 days ago"

  • 6 months ago → "6 months ago"

  • 2 years ago → "2 years ago"

  • in 10 minutes → "in 10 minutes"


fun Instant.toRelativeTime(now: Instant = Clock.System.now()): String(source)

Returns a relative time string from an Instant compared to now. Example: someInstant.toRelativeTime() → "3 hours ago"