How to set default time of ion-datetime?

2019-08-20 02:40发布

问题:

I am trying to set the default time of this datetime picker to 0800. Any idea how i can do this?

<ion-label floating>Time: From</ion-label>
          <ion-datetime displayFormat="HH:mm" pickerFormat="HH:mm" [(ngModel)]="request.from" ></ion-datetime>

回答1:

try something like :

<ion-item>
  <ion-label>Date</ion-label>
  <ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="myDate"></ion-datetime>
</ion-item>

JS:

$scope.myDate = "2017-08-08 11:22:00";


回答2:

In my case, I'll receive the wrong date format from the DB side. So, will change to the below formate. and it will work like other normal variables no extra settings or anything will be required for that.

<ion-item>
  <ion-label>Date</ion-label>
  <ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="myDate"></ion-datetime>
</ion-item>

Date format for ion-datetime must be like:

this.myDate = 2018-12-24T13:03:38.136Z;

So, make sure you are receiving valid date formate.