Locale time on IONIC2 Datetime picker

2019-09-04 05:24发布

问题:

I'm working with IONIC2, Angular2 and Typescript. I have an Datetime working as follows:

page.html

<ion-datetime displayFormat="DD MMMM YYYY" pickerFormat="DD MMMM YYYY" [(ngModel)]="date"></ion-datetime>

page.ts

  date: string = new Date().toISOString();

The ion-datetime field shows time with an hour less, how can I display date on Datetime picker considering the timezone?

回答1:

Reading this answer I solve my problem. Finally I use:

moment(new Date().toISOString()).locale('es').format();

Thanks to sebaferreras



回答2:

the simplest is to remove timezone offset in milliseconds:

date = new Date();
myDate: String = new Date(this.date.getTime() - 
                 this.date.getTimezoneOffset()*60000).toISOString();