熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JavaScript實現頁面實時顯示當前時間的簡單實例

2022-06-13   來源: JSP教程 
這篇文章介紹了頁面實時顯示當前時間的簡單實例有需要的朋友可以參考需要   復制代碼 代碼如下:

  
<html>
<head>
<title>JavaScript實現頁面實時顯示當前時間</title>
</head>
<body>
<script language="javascript">
function showtime()
{
var todayhoursecondminuteyearmonthdate;
var strDate ;
today=new Date();
var n_day = todaygetDay();
switch (n_day)
{
case :{
strDate = "星期日"
}break;
case :{
strDate = "星期一"
}break;
case :{
strDate ="星期二"
}break;
case :{
strDate = "星期三"
}break;
case :{
strDate = "星期四"
}break;
case :{
strDate = "星期五"
}break;
case :{
strDate = "星期六"
}break;
case :{
strDate = "星期日"
}break;
}
year = todaygetYear();
month = todaygetMonth()+;
date = todaygetDate();
hour = todaygetHours();
minute =todaygetMinutes();
second = todaygetSeconds();
if(month<) month=""+month;
if(date<) date=""+date;
if(hour<) hour=""+hour;
if(minute<) minute=""+minute;
if(second<) second=""+second;
documentgetElementById(time)innerHTML = year + "年" + month + "月" + date + "日 " + strDate +" " + hour + ":" + minute + ":" + second; //顯示時間
setTimeout("showtime();" ); //設定函數自動執行時間為 ms( s)
}
</script>
<div id="time"></div>
<script language="javascript"> showtime();</script>
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20508.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.