Javascript 如何在角度材质中以日期选择器的格式显示正确的日期

Javascript 如何在角度材质中以日期选择器的格式显示正确的日期,javascript,angular,datepicker,angular-material,Javascript,Angular,Datepicker,Angular Material,我有一个角度8应用程序。我用的是资料采集器 但如果我在调用中填写日期,则get api调用: searchFor(filterRegistration: FilterByRegistrationDTO) { // tslint:disable-next-line: max-line-length console.log( this.participantService.filterParticipantsByRegistration(1, "Invited", t

我有一个角度8应用程序。我用的是资料采集器

但如果我在调用中填写日期,则get api调用:

  searchFor(filterRegistration: FilterByRegistrationDTO) {
    // tslint:disable-next-line: max-line-length
    console.log(
      this.participantService.filterParticipantsByRegistration(1, "Invited", this.startDate.toString()).subscribe(result => {       
        console.log(this.startDate.toString());
        console.log(result);
      })
    );
模板如下所示:

    <div>
      <mat-form-field  class="search-field-input">
        <input matInput [matDatepicker]="picker1" placeholder="start datum" [(ngModel)]="startDate"  />
        <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
        <mat-datepicker #picker1></mat-datepicker>
      </mat-form-field>
    </div>
然后我会得到这个错误:

core.js:12584 ERROR 
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "https://dev-engine.mijnhep.nl/api/medical/organisa…GMT%2B0200%20(Central%20European%20Summer%20Time)", ok: false, …}
error:
Start: ["The value 'Mon Oct 07 2019 12:58:46 GMT+0200 (Central European Summer Time)' is not valid for Start."]
__proto__: Object
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for https://dev-/api/medical/organisation/1/Participant/filter-by-registration?Filter=Invited&Start=Mon%20Oct%2007%202019%2012:58:46%20GMT%2B0200%20(Central%20European%20Summer%20Time): 400 Bad Request"
name: "HttpErrorResponse"
ok: false
status: 400
statusText: "Bad Request"
url: "/api/medical/organisation/1/Participant/filter-by-registration?Filter=Invited&Start=Mon%20Oct%2007%202019%2012:58:46%20GMT%2B0200%20(Central%20European%20Summer%20Time)"
__proto__: HttpResponseBase
所以我的问题是。如何在客户端填写正确的日期格式。这样就不会抛出错误了


谢谢

您可以使用JSON.stringifyyourDate使用iso日期格式

然后在服务器端使用这个值

否则,在客户端,您可以使用momentourdate.format'L'

在您的代码中,它将是:

this.participantService.filterParticipantsByRegistration(1, "Invited", JSON.stringify(this.startDate))


您可以使用javascript解析格式,也可以使用诸如矩.js或日期函数之类的库轻松包装格式。谢谢。但一个例子是为什么不格式化提交日期??而不是使用this.startDate.toString正确格式化日期?是的,OK。但是格式呢??你能举个例子吗?会很好的
this.participantService.filterParticipantsByRegistration(1, "Invited", JSON.stringify(this.startDate))
this.participantService.filterParticipantsByRegistration(1, "Invited", moment(yourDate).format('L'))