1

I'm working on an application that will have an input field as DATE.
Which changes daily, Based on the date the data will be displayed.

I got the solution to my problem in HTML5 Input Type Date -- Default Value to Today? this discussion .

But when i tried to code in intel XDK .its not displaying todays date . Here is the code.

var date = new Date();

var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();

if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;

var today = year + "-" + month + "-" + day;       
document.getElementById("theDate").value = today;
<input type="date" id="theDate">

I have tried same code in my project . But it gives result likeenter image description here

Thanks in advance.....

4

1 回答 1

0

Moment.js 很有帮助Moment.js帮助了我。感谢您的回复.. :)

  1. 首先将 Moment.js 文件导入您的代码。
  2. document.getElementById('today').value = moment().format('YYYY-MM-DD');
  3. 在自动加载页面的单独函数中使用上述代码。

感谢您的回复。

于 2015-11-15T09:53:29.077 回答