-
//一般情况显示的是server端当前时间,可能会跟client时间不一样,访问者还是想看到当前client时间,所以用javascript比较方便。
-
<script language="JavaScript" type="text/javascript">
-
var timerID = null;
-
var timerRunning = false;
-
function stopclock ()
-
{
-
if(timerRunning)
-
clearTimeout(timerID);
-
timerRunning = false;
-
}
-
function startclock ()
-
{
-
stopclock();
-
showtime();
-
}
-
function showtime ()
-
{
-
var now = new Date();
-
var years = now.getFullYear();
-
var months = now.getMonth()+1;
-
var dates = now.getDate();
-
var hours = now.getHours();
-
var minutes = now.getMinutes();
-
var seconds = now.getSeconds();
-
var day;
-
if(now.getDay()==0) day = "星期日"
-
if(now.getDay()==1) day = "星期一"
-
if(now.getDay()==2) day = "星期二"
-
if(now.getDay()==3) day = "星期三"
-
if(now.getDay()==4) day = "星期四"
-
if(now.getDay()==5) day = "星期五"
-
if(now.getDay()==6) day = "星期六"
-
var timeValue = "" +((hours >= 12) ? "今天下午 " : "今天上午 " )
-
timeValue += day + " "
-
timeValue += years + "-"
-
timeValue += ((months<10) ? "0" : "") + months + "-"
-
timeValue += ((dates<10) ? "0" : "") + dates + " "
-
timeValue += ((hours >12) ? hours -12 :hours)
-
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
-
timeValue += ((seconds < 10) ? ":0" : ":") + seconds+" "
-
document.clock.thetime.value = timeValue;
-
timerID = setTimeout("showtime()",1000);
-
timerRunning = true;
-
}
-
</script>
-
<body οnlοad="startclock()">
-
<form id="clock" runat="server">
-
<input name="thetime" style="font-size: 9pt; color: #000000; border: 0" size="40" />
-
</form>
-
</body>
网页动态显示当前时间
最新推荐文章于 2021-05-18 08:08:46 发布