最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set default date in ion-datetime in Ionic 2 - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Apr 26, 2020 at 10:28 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Nov 28, 2017 at 8:36 user2828442user2828442 2,5257 gold badges67 silver badges120 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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();
发布评论

评论列表(0)

  1. 暂无评论