我正在尝试构建一个时钟输出网络应用程序,以节省数据库时间,但是由于我是php js的新手,所以我只需要指针或正确的方向即可。阅读材料或类似的内容也会有所帮助。我尝试了谷歌,但没有找到我想要的东西。 感谢您的帮助。
答案 0 :(得分:0)
由于您尚未解释自己的困境或到目前为止所取得的成就,因此我无法理解您的需求;无论如何,我只是举一个例子,如何使用JavaScript显示时钟。这将从客户端计算机获取时间并显示它。
<html>
<head>
<title>Clock</title>
<script type="text/javascript">
function showtime(){
if (!document.all & !document.getElementById)
return
thelement=document.getElementById? document.getElementById("DigitalClock"): document.all.DigitalClock
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="PM"
if (hours<12)
dn="AM"
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
thelement.innerHTML= ctime
setTimeout("showtime()",1000)
}
window.onload=showtime
var activeElemId;
function activateItem(elemId) {
document.getElementById(elemId).className="current";
if(null!=activeElemId) {
document.getElementById(activeElemId).className="";
}
activeElemId=elemId;
}
</script>
</head>
<body>
Digital Clock
<div class="panel-body" id="DigitalClock" style="font-size:25px;"></div>
</body>
</html>