codetrix - v1.5.0
    Preparing search index...

    Function formatRelative

    • Returns a human-readable string describing how far a given date is from today.

      Parameters

      • date: Date

        The Date object to compare with today.

      Returns string

      A relative time string like 'today', 'tomorrow', 'yesterday', or 'X days ago' / 'in X days'.

      formatRelative(new Date()); // 'today'
      formatRelative(new Date(Date.now() + 86400000)); // 'tomorrow'
      formatRelative(new Date(Date.now() - 2 * 86400000)); // '2 days ago'