<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