How to set current time and date in html input value by js

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

Categories: web designing javascript

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Related Blogs

Request For Demo