A simple small example to achieve the current time, the JS code is as follows:
function getdate () {
var date = new Date ();
var mon = date.getmonth () + 1; GetMonth () returns 0-11, plus 1 is required.
if (Mon <=9) {//if less than 9, you need to add 0
Mon = "0" + mon;
}
var day = Date.getdate (); GETDATE () returns 1-31, no additional 1 is required
if (day <=9) {//if less than 9, you need to add 0
Day = ' 0 ' + day;
}
document.getElementById ("Acc_time"). Value = Date.getfullyear () + "-" + Mon + "-" + day;
}
Here is the HTML code:
<input id= "Acc_time" class= "Form-control" name= "Acc_time" type= "text" onchange= "getdate ()" onkeyup= "getdate ()"/ >
OnChange () and onkeyup () Two events are intended to allow the user to change the contents of a text box.
Notes (get other date formats):
var date = new Date ();
Date.getyear (); //Get Current year (2-bit)
Date.getfullyear (); //Get the full year (4-bit, 1970-????)
Date.getmonth (); //Get the current month (0-11, 0 for January)
Date.getdate (); //Get current day (1-31)
Date.getday (); / /Get Current week x (0-6, 0 for Sunday)
Date.gettime (); //Get current time (number of milliseconds from 1970.1.1 onwards)
Date.gethours (); //Get current hours (0-23)
Date.getminutes (); //Gets the current number of minutes (0-59)
Date.getseconds (); //Gets the current number of seconds (0-59)
Date.getmilliseconds (); //Gets the current number of milliseconds (0-999)
date.tolocaledatestring (); //Get current date
Var mytime= Date.tolocaletimestring (); //Get current time
Date.tolocalestring (); //Get date and time
JS (Gets the current time and is represented in the 2015-01-01 format)