angular date To String code example
Example 1: string to date angular
let dateString = '02/05/2020';
let momentVariable = moment(dateString, 'MM-DD-YYYY');
let stringvalue = momentVariable.format('YYYY-MM-DD');
console.log(stringvalue);
Example 2: ts change date format
import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction(){
this.date=new Date();
let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');
}
Example 3: pipe of date angular
content_copy
{{ dateObj | date }}
{{ dateObj | date:'medium' }}
{{ dateObj | date:'shortTime' }}
{{ dateObj | date:'mm:ss' }}
Example 4: angular date pipe
<p>{{myDate | date: 'dd-MM-yyyy'}}</p>
myDate: Date = new Date();
Example 5: show timestamp as yyyy mm dd html angular
import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction(){
this.date=new Date();
let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');
}
Example 6: show timestamp as yyyy mm dd html angular
import { DatePipe } from '@angular/common'
...
providers: [DatePipe]