How to set current time and date in html input value by js
Sometimes there is a need to set the current date or time in input like in inquiry form, registration form, fee receipt form. We can easily set the current date and time in js by using some simple steps; here are some steps following:
Solution :
Step1 : The First Step is to put id ="currentDate" in your HTML date input like this :
<input id="currentDate" type="date" />
Step2 : Same as the First Step is to put id ="currentTime" in your HTML time input like this :
<input id="currentDate" type="time" />
Step3 :Paste this below code in your HTML file before closing the body tag
var date = new Date();
var currentDate = date.toISOString().slice(0,10);
var currentTime = date.getHours() + ':' + date.getMinutes();
document.getElementById('currentDate').value = currentDate;
document.getElementById('currentTime').value = currentTime;
I hope this code will help you, enjoy coding....