郭奇靂
郭奇靂

Reputation: 71

Ionic 3 date picker initial value

Now I use date picker to show a calendar, if I want to show a date that was the user choose previous.e.g.2011/01/01 and I want it show January of 2011 not today's date February 2018.

Upvotes: 0

Views: 1110

Answers (1)

Mahesh Jadhav
Mahesh Jadhav

Reputation: 1089

Your question is unclear but if you want to show the default date as January 11 instead of the current date you can use this solution

Ionic uses the ISO 8601 datetime format for its value as mentioned in ionic official docs

So all you need to do is parse in the ISO string date format instead of the date object itself with your desired date

In your .ts file:

this.myDate = new Date('2011-01-11').toISOString(); // pass the date which you want to set as default date

and use that variable to bind it to your ion-datetime in your HTML:

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

Upvotes: 1

Related Questions