How to remove the Date 00:00:00.000000 in this 2022-08-07 00:00:00.0000000 format?
<mat-form-field appearance="fill">
<mat-label>Date</mat-label>
<input matInput type="date" formControlName="Date">
</mat-form-field>
this.Form = this.fb.group({
deliveryDate: [this.formatDate(new Date()), Validators.required],
})
formatDate(date:Date){
return formatDate(date, this.dateFormat, this.language)
}
CodePudding user response:
You can use angular's datepipe here.
On your app.module.ts, add datepipe like below:
import { DatePipe } from '@angular/common'
...
providers: [DatePipe]
Then, on your typescript file, do like below:
formatDate(date:Date){
let formattedDate=this.datepipe.transform(this.date, 'yyyy-MM-dd');
return formattedDate;
}
CodePudding user response:
formatDate(date:Date){
var year = date.getFullYear();
var month = (date.getMonth() 1).toString().padStart(2, "0");
var day = date.getDate().toString().padStart(2, "0");
var newDate = year "-" month.toLocaleString() "-" day;
return newDate
}