我是 Angular 的新手,我正在使用 matDatepicker,一切正常,除了当我提出发布请求并检查我的请求标题时,我发现发送的日期比我选择的日期早 1 天,例如,如果我选择 01/08/2020,它会发送 01/07/2020,并且发送的日期显示为:2020-01-07T22:00:00.000Z,我已经到处搜索有关此问题的信息,但不是就我而言,我非常感谢您的帮助。
员工.component.html
<input matInput [matDatepicker]="picker" placeholder="Choose a date" [ngModel]="hiringDate"
class="form-control" formControlName="HiringDate">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
员工.component.ts
this.editProfessionalInfoForm = this.fb.group({
HiringDate: new FormControl({value: '' }, [Validators.required])
})
onSubmit() {
this.submitted = true;
if (this.editEmployeeForm.invalid) {
this.loading = false;
return;
}
this.restService.AddPersonalInfo(this.editEmployeeForm.value,
this.urlId).subscribe((res: any) => {
this.loading = false;
this.translate.get('alert.savedSuccess').subscribe((res: string) => {
this.toastr.success(res);
});
})
}
最佳答案
在您的 service.ts 中添加日期类型 toLocaleString()
关于javascript - matDatepicker 在选择日期前 1 天发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59643708/