Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...