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>
dateChange(){
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.
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.