Search code examples
javascripthtmldateintel-xdkintel-xdk-contacts

how to set today's date as default and will change everyday in INTEL XDK?


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.....


Solution

  • Moment.js is very helpful Moment.js helped me. Thanks for your replies .. :)

    1. First import Moment.js file into your code.
    2. document.getElementById('today').value = moment().format('YYYY-MM-DD');
    3. Use the above piece of code in the separate function where the page gets automatically loaded.

    Thanks for replies.