如何在Ionic 2的ion-datetime中设置默认日期 [英] How to set default date in ion-datetime in Ionic 2

查看:103
本文介绍了如何在Ionic 2的ion-datetime中设置默认日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 page.html 表单上,我有 ion-datetime 字段,单击该字段时,离子日历为打开以选择所需的日期。我希望它在打开表单时显示当前日期。我正在尝试使用以下代码,但仍显示空白字段。

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.

页面.html 代码:

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

page.ts 代码:

 public myDate=new Date();

如何在HTML页面上显示当前日期?

How can I show current date on my HTML page?

推荐答案

您需要以 ISO 8601日期时间格式:YYYY-MM-DDTHH:mmZ (根据文档)。

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

这篇关于如何在Ionic 2的ion-datetime中设置默认日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆