Skip to content

Instantly share code, notes, and snippets.

@pimatco
Created February 7, 2018 15:46
Show Gist options
  • Save pimatco/ca5f9c4dc89f84679d72390e0715aa04 to your computer and use it in GitHub Desktop.
Save pimatco/ca5f9c4dc89f84679d72390e0715aa04 to your computer and use it in GitHub Desktop.
Pipe with timeago for Angular
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
//insert your locale
moment.locale('pt-br');
@Pipe({
name: 'timeago',
})
export class TimeagoPipe implements PipeTransform {
transform(value) {
//formats the value to make sure its moment
let formatted = moment().format(value);
//convert to timeago
let timeAgo = moment(value).fromNow();
return timeAgo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment