日期:2014-05-20 浏览次数:20608 次
<script language="javascript" type="text/javascript"> function showSysTime(divName) { var date = new Date(); //日期对象 var now = ""; now = date.getFullYear() + "年"; //读英文就行了 now = now + (date.getMonth() + 1) + "月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了 now = now + date.getDate() + "日"; now = now + date.getHours() + "时"; now = now + date.getMinutes() + "分"; now = now + date.getSeconds() + "秒"; document.getElementById(divName).innerHTML = now; //div的html是now这个字符串 setTimeout("showSysTime('"+divName+"')", 1000); //设置过1000毫秒就是1秒,调用show方法 } </script> <div id="nowDiv" > </div> <script language="javascript" type="text/javascript"> showSysTime("nowDiv"); </script>
------解决方案--------------------
要在网页里动态显示当前是吗,
加一个控件 ID="labnow"
<asp:Label ID="labnow" runat="server" Width="138px">
然后在 </head> </head> 里面加入下面一段 注意 控件id
<script type ="text/javascript" >
setInterval("labnow.innerText=new Date().toLocaleTimeString ()",1000)
</script>
------解决方案--------------------
JavaScript300例里有时间实时变化的效果。
你百度一下,或者到下载区搜索一下应该会找到满意的。
------解决方案--------------------
function showtime()
{
var now = new Date();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
var m2="";
var s2="";
if(m<10)m2="0"+m;
else m2=m;
if(s<10)s2="0"+s;
else s2=s;
var txt = h+":"+m2+":"+s2;
var p = document.getElementById("txt_time");
p.value="现在时刻:"+txt;
setTimeout("showtime()",1000);
}
<body onload="showtime()">
或用定时器显示时间
------解决方案--------------------
<HTML> <HEAD> <TITLE>时间日期篇--显示时钟</TITLE> </HEAD> <BODY bgcolor="#fef4d2" onload=showclock() background="../images/background2.jpg"> <br> <br> <center> <font color="ffaafa"> <h2><font color="#FF00FF"><b>时间日期篇--显示时钟</b></font></h2> </font> <hr width=300> <br><br> <!-- 案例代码开始 --> <!-- [Step1]: 这里可以调整时钟的方位 --> <span id=liveclock style=position:absolute;left:250px;top:122px;; width: 109px; height: 15px> </span> <SCRIPT language=javascript> function showclock() {if(!document.layers&&!document.all) return var Digital=new Date() var hours=Digital.getHours() var minutes=Digital.getMinutes() var seconds=Digital.getSeconds() var dn="AM" if(hours>12){dn="PM" hours=hours-12 }if(hours==0) hours=12 if(minutes<=9) minutes="0"+minutes if(seconds<=9) seconds="0"+seconds <!-- [Step2]:这里可以改变时钟的大小 --> myclock="<font size='5' face='Arial'><b>"+hours+":"+minutes+":" +seconds+" "+dn+"</b></font>" if(document.layers){document.layers.liveclock.document.write(myclock) document.layers.liveclock.document.close() }else if(document.all) liveclock.innerHTML=myclock setTimeout("showclock()",1000) } </SCRIPT> <!-- 案例代码结束 --> </center></BODY> </HTML>