Locale time on IONIC2 Datetime picker

爷,独闯天下 提交于 2019-12-11 04:13:37

问题


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();


来源:https://stackoverflow.com/questions/39611380/locale-time-on-ionic2-datetime-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!