I am sending an object containing two dates from Angular 6 to a ASP.NET Core Web API method. The dates are correct on the Angular side, but when they are received in the Web API method, they are one day behind from what they were went being sent from the Angular application.
startSprint(id: number, SprintDates: any): Observable<any> {
this.sprintId = id.toString();
return this.http.patch<any>(this.baseUrl + 'setSprintDates/' + this.sprintId,
SprintDates);
}
The above method sends dates object to the Web API method. The method below is the Web API method that receives that object, but when I debug and hover the cursor over the sprintDatesDto object, the values received are one day behind what they were when sent from Angular.
[HttpPatch("setSprintDates/{sprintId}")]
public async Task<IActionResult> SetSprintDates(string sprintId, SprintDatesDto sprintDatesDto)
{
// Business login related code
return StatusCode(200);
}
This is the SprintDatesDto class:
namespace AgileFootPrints.API.Dtos
{
public class SprintDatesDto
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
}
This is the object i created in angular Typescript file:
sprinDates = {
startDate: Date,
endDate: Date
};
Then below, in Html file i have used ngModel to bind to sprintDates object properties:
<div class="row">
<div class="col-md-7 w-100 ">
<mat-form-field class="example-full-width">
<input
matInput
[(ngModel)]="sprinDates.startDate"
[min]="minDate"
[max]="maxDate"
[matDatepicker]="startsAt"
placeholder="Starts At"
/>
<mat-datepicker-toggle matSuffix [for]="startsAt"></mat-datepicker-toggle>
<mat-datepicker #startsAt></mat-datepicker>
</mat-form-field>
</div>
<br />
</div>
<div class="row">
<div class="col-md-7 w-100">
<mat-form-field class="example-full-width">
<input
[disabled]="sprinDates.startDate === undefined"
matInput
[(ngModel)]="sprinDates.endDate"
[min]="sprinDates.startDate"
[max]="maxDate"
[matDatepicker]="endsAt"
placeholder="Ends At"
/>
<mat-datepicker-toggle matSuffix [for]="endsAt"></mat-datepicker-toggle>
<mat-datepicker #endsAt></mat-datepicker>
</mat-form-field>
</div>
</div>
SprintDateson client side?