Home > Mobile >  day incorrect in angular material datepicker -day before the exact date
day incorrect in angular material datepicker -day before the exact date

Time:10-24

hello When I select a date I see the correct date in the field but, when I save, the datepicker send the day before the date. i use datetime picker range code html:

<mat-form-field appearance="fill">
      <mat-label>Enter a date range</mat-label>
      <mat-date-range-input  [rangePicker]="picker" separator="to" required [min]="today" [dateFilter]="dateFilterFn">
        <input matStartDate formControlName="From_Date" placeholder="From_Date" name="From_Date">
        <input matEndDate formControlName="To_Date" placeholder="To_Date" name="To_Date">
      </mat-date-range-input>
       <mat-hint>DD/MM/YYYY – DD/MM/YYYY </mat-hint>
      <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
      <mat-date-range-picker #picker></mat-date-range-picker>

    </mat-form-field>

Code Ts

   this.demandeForm = this.formBuilder.group({
      From_Date: ['',Validators.required],
     To_Date :['',Validators.required],
      Created_AT : [this.created_AT,Validators.required],
      nmbJours : ['',Validators.required])}

Someone can help me

CodePudding user response:

If the date picker sent the date range to API using http with Json format the date is converted to UTC, try look in this exemple:

var date = new Date()
console.log(date)
console.log(date.toLocaleString())
console.log(date.toJSON())

//output:
// Sun Oct 23 2022 20:52:40 GMT 0300 (your local time zone mine is "GMT 0300")
// 23/10/2022, 20:52:40
// 2022-10-23T17:52:40.497Z
  • Related