get Date in angular code example

Example 1: angular get current date yyyy-mm-dd

import { DatePipe } from '@angular/common';

@Component({
    templateUrl: './name.component.html',
    styleUrls: ['./name.component.scss'],
    providers: [DatePipe]
})

myDate = new Date();
constructor(private datePipe: DatePipe){
    this.myDate = this.datePipe.transform(this.myDate, 'yyyy-MM-dd');
}

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);

Example 3: show timestamp as yyyy mm dd html angular

import { DatePipe } from '@angular/common'
...
providers: [DatePipe]