JavaScript总结(2)-网页上显示时间
显示效果如图所示:
代码如下
HooHoo提醒您,现在是9月28日 15:34:26 |
代码如下
<TABLE>
<TR>
<TD><span id="localtime"></span>
<script>
function showLocale(objD)
{
var dn, str;
var hh = objD.getHours();
var mm = objD.getMinutes();
var ss = objD.getSeconds();
str = (objD.getMonth() + 1) + "月" + objD.getDate() +"日";
if(hh<10) hh = '0' + hh;
if(mm<10) mm = '0' + mm;
if(ss<10) ss = '0' + ss;
str += " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
</script>
</TD>
</TR>
</TABLE>
<TR>
<TD><span id="localtime"></span>
<script>
function showLocale(objD)
{
var dn, str;
var hh = objD.getHours();
var mm = objD.getMinutes();
var ss = objD.getSeconds();
str = (objD.getMonth() + 1) + "月" + objD.getDate() +"日";
if(hh<10) hh = '0' + hh;
if(mm<10) mm = '0' + mm;
if(ss<10) ss = '0' + ss;
str += " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
</script>
</TD>
</TR>
</TABLE>
作者:青羽