ionic 2 ion-datetime ISO Format issue

前端 未结 3 860
不思量自难忘°
不思量自难忘° 2020-12-20 17:34

I am using ion-datetime for my appointment form. While inserting it is working fine without any problem. But when I need to update the inserted appointment date form details

3条回答
  •  眼角桃花
    2020-12-20 18:16

    Using ISO format before displaying, like this:

    this.myDate = new Date('2017-01-01').toISOString()
    

    Will give us a difference of hours, each browser would do something different. In my case I had a difference of 5 hours (16/12/17 02:00 would be 16/12/17 07:00).

    A better way would be to use moment as ionic recomends on its documentationn (https://ionicframework.com/docs/api/components/datetime/DateTime/#advanced-datetime-validation-and-manipulation)

    Example:

    1. Open console at root proyect and install moment: npm install moment --S.
    2. Import moment in component file: import moment from 'moment';.
    3. Set value of model variable: this.myDate = moment().format().

    The best would be create a pipe. Well check this demo http://plnkr.co/edit/MHjUdC for inspiration, goog luck :)

提交回复
热议问题