RepositoryTypeScriptGRGreece
ihym

ihym/ngx-timeago

⏰ Live updating timestamps in Angular

80stars
14forks
2issues
3views

ngx-timeago npm version npm License: MIT

Live updating timestamps in Angular.

https://ihym.github.io/ngx-timeago/

Get the complete changelog here: https://github.com/ihym/ngx-timeago/releases

Installation

First you need to install the package:

pnpm add ngx-timeago

Choose the version corresponding to your Angular version:

Angularngx-timeago
204.x+
16,17,18,193.x+
10,11,12,13,14,152.x+
6,7,8,91.x+

Setup

ngx-timeago supports both standalone components and NgModule approaches.

// main.ts
import { provideTimeago } from 'ngx-timeago';

bootstrapApplication(AppComponent, {
  providers: [provideTimeago()],
});
// component.ts
import { TimeagoPipe } from 'ngx-timeago';

@Component({
  standalone: true,
  imports: [TimeagoPipe],
  template: `{{ date | timeago }}`,
})
export class MyComponent {}

With custom configuration:

provideTimeago({
  formatter: { provide: TimeagoFormatter, useClass: CustomFormatter },
  clock: { provide: TimeagoClock, useClass: MyClock },
  intl: { provide: TimeagoIntl, useClass: CustomIntl },
});

NgModule Approach

import { TimeagoModule } from 'ngx-timeago';

@NgModule({
  imports: [TimeagoModule.forRoot()],
})
export class AppModule {}

With custom configuration:

TimeagoModule.forRoot({
  formatter: { provide: TimeagoFormatter, useClass: CustomFormatter },
  clock: { provide: TimeagoClock, useClass: MyClock },
  intl: { provide: TimeagoIntl, useClass: CustomIntl },
});

For lazy loaded modules, use forChild() instead of forRoot().

Usage

Using the Pipe

<div>{{ date | timeago }}</div>
<div>{{ date | timeago: live }}</div>

Using the Directive

<div timeago [date]="date"></div>
<div timeago [date]="date" [live]="live"></div>

The live parameter controls automatic updates (default: true).

Configuration

Internationalization (I18n)

By default, there is no intl service available, as the default formatter doesn't provide language support. You should provide one, if you end up with a formatter that needs it (either TimeagoCustomFormatter which is provided by the lib or your own). The purpose of the intl service is to contain all the necessary i18n strings used by your formatter.

export class MyIntl extends TimeagoIntl {
  // Customize strings
}

// Then provide it with TimeagoCustomFormatter
provideTimeago({
  intl: { provide: TimeagoIntl, useClass: MyIntl },
  formatter: { provide: TimeagoFormatter, useClass: TimeagoCustomFormatter },
});

There is support for a large number of languages out of the box. This support is based on the string objects taken from jquery-timeago.

To use any of the languages provided, you will have to import the language strings and feed them to the intl service.

import { Component } from '@angular/core';
import { TimeagoIntl } from 'ngx-timeago';
import { strings as englishStrings } from 'ngx-timeago/language-strings/en';

@Component({...})
export class MyComponent {
  constructor(private intl: TimeagoIntl) {
    this.intl.strings = englishStrings;
    this.intl.changes.next();
  }
}

See available languages.

Custom Formatter

Implement TimeagoFormatter to customize timestamp display:

import { TimeagoFormatter } from 'ngx-timeago';

export class CustomFormatter extends TimeagoFormatter {
  format(then: number): string {
    const seconds = Math.round(Math.abs(Date.now() - then) / 1000);
    if (seconds < 60) return 'just now';
    if (seconds < 3600) return Math.round(seconds / 60) + ' minutes ago';
    // ... your logic
  }
}

Then provide it: { provide: TimeagoFormatter, useClass: CustomFormatter }

See full example

Custom Clock

Implement TimeagoClock to control update intervals:

import { TimeagoClock } from 'ngx-timeago';
import { interval } from 'rxjs';

export class MyClock extends TimeagoClock {
  tick(then: number) {
    return interval(2000); // Update every 2 seconds
  }
}

Then provide it: { provide: TimeagoClock, useClass: MyClock }

See full example

Contribute

$ pnpm install
$ pnpm build:lib
$ pnpm start              # NgModule demo
$ pnpm start:standalone   # Standalone demo

Both demos available at http://localhost:4200


MIT © Vasilis Diakomanolis

Similar Projects

Discover other similar projects and AI models.

RepositoryTypeScript
hustcc/timeago.js

:clock8: :hourglass: timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.

5.4k
Nov 25, 2026
RepositoryTypeScript
help-me-mom/ng-mocks

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup

1.2k
Nov 25, 2026
RepositoryTypeScript
AndrewPoyntz/time-ago-pipe

An Angular pipe for converting a date string into a time ago

127
Jan 11, 2023
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
RepositoryTypeScript
nilbuild/developer-roadmap

Interactive roadmaps, guides and other educational content to help developers grow in their careers.

373.1k
Dec 1, 2026
RepositoryTypeScript
firecrawl/firecrawl

Firecrawl is the knowledge infrastructure to make your agents smarter. It connects your agents to the web, and to Alexandria, our library of everything else.

215.1k
Dec 2, 2026
RepositoryTypeScript
vuejs/vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

212.6k
Oct 10, 2024
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026