0

I am working on an angular 11 project. I want to display current time and date and the time should change for every minute.

I tried with new Date(). But it shows only the time when the program run time.

This is what I tried. But it does not works for me

.ts file

  today= Date.now();
  UKDataTime = '';

  this.UKDataTime = formatDate(this.today, 'dd-MM-yyyy hh:mm:ss a', 'en-US', '+0100');

.html file

 <p class="current-time">UK: {{UKDataTime}}</p> 

What can i do display live time in angular 11?

hanushi
  • 119
  • 6
  • 14

2 Answers2

1

You need to change date value every second for example you can use setInterval for this

setInterval(() => {
    this.UKDataTime = formatDate(Date.now(), 'dd-MM-yyyy hh:mm:ss a', 'en-US', '+0100');
}, 1000)
ZloiGoroh
  • 411
  • 4
  • 11
0

Use rxjs timer

timer(0,1000).pipe(map(x => new Date())).subscribe(console.log);
enno.void
  • 6,242
  • 4
  • 25
  • 42