I know there are several threads about this and i read them all but couldn't fix this for days. I might found a solution but it seems to be do dirty for me.
So as other users I have the same problem with the datePicker. For me it's the Angular Material Datepicker mat-datepicker
When I log the value I get the correct result:
Wed Dec 24 1999 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)
but in the request it is
1999-12-23T23:00:00.000Z
What I tried yet:
I've added { provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
to my component
and to my app.module.ts
. That does not make any difference for me.
My dirty solution (before sending the request):
let newDate= new Date(this.personalForm.get("dateOfBirth").value);
newDate.setMinutes(newDate.getMinutes() - newDate.getTimezoneOffset());
When I am doing this the console logs:
Wed Dec 24 1999 01:00:00 GMT+0100 (Mitteleuropäische Normalzeit)
and the request is right:
1997-12-24T00:00:00.000Z
But if somebody now would be from a different timezone like GMT-0100 this would again not work. How to fix this correctly?
I also change the adapter dynamically if it's necessary to know:
this._adapter.setLocale(this.translateService.currentLang);