angular datetime get time now code example

Example 1: angular get current time

import { Component } from '@angular/core';
@Component({
    selector: 'my-app',
    template: `{{ now }}`
})
export class AppComponent {
    public now: Date = new Date();

    constructor() {
        setInterval(() => {
          this.now = new Date();
        }, 1);
    }
}

Example 2: how to display current date and time in angular

//reload the page for evry one minute...put the below code in ngOnInit function

setTimeout(
      function(){ 
      location.reload(); 
      }, 60000);