如何在页上实时显示时间(用JAVASCRIPT)

ufc 2000-05-22 06:14:00
...全文
295 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
songnuan 2000-06-12
  • 打赏
  • 举报
回复
代码如下:
<html>
<head>
<script language="javascript">
<!--
var timeStr,dateStr;
function clock()
{
now=new Date();
hours=now.getHours();
minutes=now.getMinutes();
seconds=now.getSeconds();
timeStr=""+hours;
timeStr+=((minutes<10)?":0":":")+minutes;
timeStr+=((seconds<10)?":0":":")+seconds;
clock1.innerHTML=timeStr;
window.setTimeout("clock()",1000);
}
//-->
</script>
</head>
<BODY onLoad="clock();">
<div id="clock1" style="position:absolute;top:185;left:705;font-family:Georgia;font-size:17;color:red;">
</div>
</html>
dickwolf 2000-06-07
  • 打赏
  • 举报
回复
先用javascript写函数tick()
源码如下:
<script Language="JavaScript"><!--
function tick()
{
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var intYear,intMonth,intDate;
var curYear,curMonth,curDate;
var today;

today = new Date();

intYear=today.getYear();
intMonth=today.getMonth();
intDate=today.getDate();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();

curYear=intYear+"年";
curMonth=intMonth+1+"月";
curDate=intDate+"日";

if (intHours == 0)
{
hours = "12:";
xfile = "午夜";
}
else
if (intHours < 12)
{
hours = intHours+":";
xfile = "上午";
}
else
if (intHours == 12)
{
hours = "12:";
xfile = "正午";
}
else
{
intHours = intHours - 12
hours = intHours + ":";
xfile = "下午";
}


if (intMinutes < 10)
{
minutes = "0"+intMinutes+":";
}
else
{
minutes = intMinutes+":";
}


if (intSeconds < 10)
{
seconds = "0"+intSeconds+" ";
}
else
{
seconds = intSeconds+" ";
}

timeString ="现在是"+curYear+curMonth+curDate+xfile+hours+minutes+seconds;

Clock.innerHTML = timeString;

window.setTimeout("tick();", 100);
}

window.onload = tick;
-->
</script>

然后在页面源文件中添加如下代码即可
<!--显示当前日期和时间-->
<div id="Clock" align="center" style="font-size: 24; color:#000fff"></div>

myww 2000-06-07
  • 打赏
  • 举报
回复
源程序如下:copy 即可。
<script language="JavaScript"> <!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=black>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT COLOR=black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=black>:</FONT></BLINK>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? "<FONT COLOR=blue><I><B>pm</B></I></FONT>" : "<FONT COLOR=blue><B><I>am</I></B></FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期三","<font color=black>星期四","<font color=black>星期五","<font color=GREEN>星期六"); document.write("<font color=black>19<font color=black>",today.getYear(),"<font color=red>年","<font color=black>",today.getMonth()+1,"<font color=red>月","<font color=black>",today.getDate(),"<font color=red>日 </FONT>",d[today.getDay()+1]," ",timeValue); //--></script>
BareHead 2000-05-25
  • 打赏
  • 举报
回复
源代码如下,照单copy就可以了,分数一定要给我哟!
<html>
<HEAD><TITLE></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=gb2312" >
</head>
<body bgcolor=#FFFFFF>
<script language=JavaScript>
function changeTime()
{
var curdate=new Date();
window.sss.innerText=curdate;
}
setInterval("changeTime()",1000);
</script>
<div id=sss>
这里随便写点什么
</div>
</body>
</html>
WHQ 2000-05-22
  • 打赏
  • 举报
回复
用setInterval设一个定时器,在此定时器的函数中刷新显示时间的表单内容不就成了

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧