Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Make pipe refresh it self in angular

I have static timestamp from backend and I want to refresh the pipe every 1 second to get date from now and this my pipe

    import { Pipe, PipeTransform } from '@angular/core';
import moment from 'moment';
@Pipe({
  name: 'dateFormat'
})
export class DateFormatPipe implements PipeTransform {

  transform(date: string): string {

    return moment.utc(date, 'X').local().format('DD-MM-YYYY h:mm:ss a');
  }

}

in this case it just convert time stamp to this format , I want to keep date updated how can I do this ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You should return an observable and use asyncPipe as well.

import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
import { interval, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Pipe({
  name: 'dateFormat'
})
export class DateFormatPipe implements PipeTransform {

  transform(date: string): Observable<string> {
    return interval(1000).pipe(map(() => { return moment().format('DD-MM-YYYY h:mm:ss a') }));
  }

}

And you should use it like: {{ 'param' | dateFormat | async}}

about 4 years ago · Juan Pablo Isaza Report

0

I think you just have to refresh your time that is passed into the pipe every second?

Like

currentTime$ = Observable.interval(1000).pipe(map(() => { return new Date() } ))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!