社区
Java SE
帖子详情
如何在页上实时显示时间(用JAVASCRIPT)
ufc
2000-05-22 06:14:00
...全文
299
5
打赏
收藏
如何在页上实时显示时间(用JAVASCRIPT)
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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设一个定时器,在此定时器的函数中刷新显示时间的表单内容不就成了
使用
JavaScript
实时
显示
当前
时间
在本文中,我们将使用
JavaScript
编写代码来
实时
显示
当前
时间
。现在,当您在浏览器中加载该网
页
时,您将看到一个
实时
显示
当前
时间
的区域。元素来放置
时间
,并为其指定一个唯一的ID,以便我们可以通过
JavaScript
找到它...
JavaScript
实时
显示
日期
时间
网
页
里
实时
显示
当前
时间
。
时钟
实时
显示
当前
时间
(
javascript
,web)
时钟
实时
显示
当前
时间
(
javascript
,web)
JavaScript
用定时器写一个
实时
显示
时间
的
页
面
定时器 格式:setInterval(函数,毫秒值...用定时器一个
实时
显示
时间
的
页
面 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>定时器</title> <...
JavaScript
实现动态
时间
显示
功能
一、基本思路 创建showTime()函数,利用
JavaScript
中的Date对象的属性及方法获取
时间
,利用Window对象的 setInterval() 方法按照指定的周期(以毫秒计)来调用函数或计算表达式。...
显示
时间
</title> <
Java SE
62,614
社区成员
307,327
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章