Library API
    Preparing search index...

    Function getRelativeTime

    • Returns a localized relative time string using Intl.RelativeTimeFormat. Falls back to a basic string representation if formatting fails.

      Parameters

      • value: number

        The numeric value to format (e.g., 2)

      • unit: RelativeTimeFormatUnit

        The time unit (e.g., 'days', 'hours')

      • Optionallocale: string

        Optional locale string

      • style: RelativeTimeFormatStyle = 'narrow'

        The formatting style (default: 'narrow')

      • numeric: RelativeTimeFormatNumeric = 'always'

        The numeric formatting preference (default: 'always')

      Returns string

      The localized relative time string

      getRelativeTime(2, 'days', 'en'); // 'in 2 days'