user2828442
user2828442

Reputation: 2525

How to set default date in ion-datetime in Ionic 2

On my page.html form, I have ion-datetime field, on clicking it, Ionic calendar is opened to select the required date. I want it to show current date when my form is opened. I am trying with the below code but it is still showing blank field.

page.html code:

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

page.ts code:

 public myDate=new Date();

How can I show current date on my HTML page?

Upvotes: 3

Views: 4474

Answers (1)

Suraj Rao
Suraj Rao

Reputation: 29635

You need to provide date in the form of ISO 8601 Datetime Format: YYYY-MM-DDTHH:mmZ as per the documentation.

Set your initial date as:

public myDate:string=new Date().toISOString();

Upvotes: 7

Related Questions