如何删除此2022-08-07 00:00:00000000格式的日期00:00:0000000?
<mat-form-field class="full-width1" 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)
}
您可以在此处使用angular的日期管道。
在你的app.module.ts上,添加如下日期管道:
import { DatePipe } from '@angular/common'
...
providers: [DatePipe]
然后,在您的打字脚本文件上,执行以下操作:
formatDate(date:Date){
let formattedDate=this.datepipe.transform(this.date, 'yyyy-MM-dd');
return formattedDate;
}
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
}