JavaScript–動態顯示時間

來源:互聯網
上載者:User

動態顯示時間

<html>
<title></title>
<head>
<script language="JavaScript">
var timerID=null;
var timerRunning=false;
file://啟動
function startclock()
{
     stopclock();
     time();
}

file://停止
function stopclock()
{
     if(timerRunning)
     clearTimeout(timerID);
     timerRunning=false;
}

file://實現模組
function time()
{
     file://使用new操作符建立時間對象
     var now=new Date();
     var yr=now.getYear();
     var mName=now.getMonth()+1;    
     var dayNr=((now.getDate()<10)?"0":"")+now.getDate();
     var dName=now.getDay()+1;
     var ampm=(now.getHours()>=12)?"下午":"上午"
     var hours=now.getHours();
     hours=((hours>12)?hours-12:hours);
     var minutes=((now.getMinutes()<10)?":0":":")+now.getMinutes();
     var seconds=((now.getSeconds()<10)?":0":":")+now.getSeconds();

     file://判斷今天是星期幾
     if(dName==1)Day="Sunday";
     if(dName==1)Day="Monday";
     if(dName==3)Day="Tuesday";
     if(dName==4)Day="Wednesday";
     if(dName==5)Day="Thursday";
     if(dName==6)Day="Friday";
     if(dName==7)Day="Saturday";

     file://判斷月份
     if(mName==1)Month="Janauary";
     if(mName==2)Month="February";
     if(mName==3)Month="March";
     if(mName==4)Month="April";
     if(mName==5)Month="May";
     if(mName==6)Month="June";
     if(mName==7)Month="July";
     if(mName==8)Month="August";
     if(mName==9)Month="September";
     if(mName=10)Month="October";
     if(mName=11)Month="November";
     if(mName=12)Month="December";

     var DayOfWeek=(""+Day+"");
     document.forms[0].elements[0].value=DayOfWeek;
     var MonthDayYear=(""+Month+","+dayNr+","+yr+"");
     document.forms[0].elements[1].value=MonthDayYear;
     var TimeValue=(""+hours+minutes+seconds+""+ampm);
     document.forms[0].elements[2].value=TimeValue;
     timerID=setTimeout("time()",1000);
     timerRunning=true;
}
</script>
</head>
<body onLoad="startclock()">
<form>
<table border=3 width=500>
<tr>
<td align="center"><FONT COLOR=800000 SIZE=+1><STRONG>今天星期</STRONG></FONT>
<td align="center"><input type="text"NAME="local"SIZE=13 VALUE="Weekday">
</tr>
<tr>
<td align="center"><font color=800000 size=+1><strong>日期</strong></font>
<td align="center"><INPUT TYPE="text" name="local" size=22 value="日期">
</tr>
<tr>
<td align="center"><font color=800000 size=+1><strong>時間</strong></font>
<td align="center"><input type="text" name="local" size=16 value="時間">
</tr>
</table>
<br>
<table border=0 widtn=400>
<tr>
<TD align="center"><input type="button" value="停止" onclick="stopclock()">
<TD align="center"><input type="button" value="繼續" onclick="startclock()">
</tr>
</table>
</form>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.