Ion-datetime to new Date

Using the ion-datetime picker, when I pass the selected date using ionChange and then use the string in a new Date function, it is always one day behind.

However, if I add a minute to the date, it works.

<ion-datetime displayFormat="MMMM/DDD/D/YYYY" pickerFormat="MMMM/DDD/YYYY" [(ngModel)]="myDate" (ionChange)="dateChange(myDate)"></ion-datetime>

console.log("----new Date:"+new Date(this.myDate)) // creates a date one day prior
console.log("----new Date:"+new Date(this.myDate+" 00:01:00")) // create correct date


I’m not sure if this is considered a real problem but thought I’d mention it.

Just a note that ion-datetime does NOT support using javascript Date.
Instead it expects an ISO format for date,

Yes, using the following was also a work around and a good way to set the initial date.

theDate = new Date().toISOString();

<ion-datetime #dateTime displayFormat="MMMM/DDD/D/YYYY" pickerFormat="MMMM/DDD/YYYY" [(ngModel)]="theDate" (ionChange)="dateChange(myDate)"></ion-datetime>

If my server uses UTC dates and my model stores javascript date objects, do I need to use moment.js to convert ISO string dates from date picker back to a date object? If I just use new Date(IsoStringDate) it gives me the day before.

I added the moment library and am taking the value from date time picker and setting my model to moment(isoDateTimeString).toDate() and it still is a day off.