As I was working on fixing an issue with an "Invalid date" error in my ngx-bootstrap-bsDatepicker control and FormGroup, I came across a problem with the date value stored in the object this.ts.startDateTime
when compared to a new Date() object.
08:11:03.723 ts-form.component.ts:240 HZyWZhwowB - this.ts.startDateTime 2019-07-16T20:18:24.9133333
08:11:03.724 ts-form.component.ts:242 HZyWZhwowB - testDate Wed Jul 17 2019 08:11:03 GMT-0400 (Eastern Daylight Time)
08:11:03.724 ts-form.component.ts:244 HZyWZhwowB - this.ts.startDateTime instanceof Date false
08:11:03.725 ts-form.component.ts:246 HZyWZhwowB - testDate instanceof Date true
The property causing the issue is:
/**
* Gets or sets the start date.
*/
startDateTime: Date;
It's evident that the values are not the same. The object contains data fetched from an HTTP Request to a WebAPI controller, and the TypeScript interface is auto-generated from models in the WebAPI. For most parts of the application, the current Date value in the object works fine.
How can I best resolve this problem within my Angular application and convert this value into a valid date?
Angular 5 - ASP.NET API
momentjs is available in the application, but not used in my component at the moment.