Skip to main content

timeAgo

Callable

  • timeAgo(timestamp: null | Date, options?: { withAgo?: boolean }): string

  • Returns a string representing the time elapsed since the provided timestamp.

    @example
    // Get the time elapsed since a timestamp without "ago"
    const timeElapsed = timeAgo(new Date("2022-02-17T12:30:00Z"));
    console.log(timeElapsed); // Output: "1d"

    // Get the time elapsed since a timestamp with "ago"
    const timeElapsedWithAgo = timeAgo(new Date("2022-02-17T12:30:00Z"), { withAgo: true });
    console.log(timeElapsedWithAgo); // Output: "1d ago"