JS gets the current time and assigns the time to the input form

Source: Internet
Author: User
Tags builtin

<script>
Window.onload = function () {
function GetDate () {
Debugger
var today = new Date ();
var date;
Date = (Today.getfullyear ()) + "-" + (Today.getmonth () + 1) + "-" + today.getdate () + "-" + today.tolocaletimestring ();
return date;
}
Window.setinterval (function () {
document.getElementById ("Getbooktime"). Value=getdate ();
}, 1000);
}
</script>

....

<input type= "text" name= "Getbooktime" id= "Getbooktime" value= "" >

Also how to customize the date format as follows:

Select Date:<InputType=The date"Value="2011-01-04"/> Select time:<InputType=The time" value=" 22:52" /> Select week:<input type=" Week" /> Select Month:<input type="month" />
The results are as follows:
Select Date:

Select time:

Select Week:

Select Month:


Another way to do this is as follows:
< html xmlns = "http://www.w3.org/1999/xhtml" > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" /> < title >系统时间</ title > < script language = "javascript" type = "text/javascript" > <!--      //获得当前时间,刻度为一千分一秒      var initializationTime = (new Date()).getTime();      function showLeftTime() {          var now = new Date();          var year = now.getYear();          var month = now.getMonth();          var day = now.getDate();          var hours = now.getHours();          var minutes = now.getMinutes();          var seconds = now.getSeconds();          document.all.show.innerHTML = "2" + year + "年" + month + "月" + day + "日 " + hours + ":" + minutes + ":" + seconds + "";          //一秒刷新一次显示时间          var timeID = setTimeout(showLeftTime, 1000);      } //--> </ script > </ head > < body onload = "showLeftTime()" > < label id = "show" >显示时间的位置</ label > < inpu type = "text" value = "这里是要获取时间的!" /> </ body > </ html >Or as follows: < html > < head > < title >无标题文档</ title > < script > function t(){ var now= new Date(); var h=now.getHours(); var m=now.getMinutes(); var s=now.getSeconds();  if (h>=0 && h <=12) var ho=" AM"; if (h>12 && h< 24 ) var  ho = " PM" ; var  tt = h +":"+m+":"+s+ho; document.getElementById("time") .value = tt ; } setInterval(‘t()‘,500); </script> </ head > < body > < form > < input type = "text" id = "time" value = "" /> </ form > </ body > </ html >
 

 

JS gets the current time and assigns the time to the input form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.