Colin Wong
Colin Wong

Reputation: 131

How to set default time of ion-datetime?

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>

Upvotes: 0

Views: 2871

Answers (2)

Ajay Gupta
Ajay Gupta

Reputation: 2957

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.

Upvotes: 0

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";

Upvotes: 1

Related Questions