求一显示小时分钟秒的程序,要秒会变的,像这种格式19:30:56。30分只给一个人

住楼上的老丁 2003-05-21 08:02:28
求一显示小时分钟秒的程序,要秒会变的,像这种格式19:30:56。千万不要刷新的太累了
...全文
85 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
凋零的老树 2003-05-22
  • 打赏
  • 举报
回复
<script Language="JavaScript">
var timerID = null;
var timerRunning = false;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var year = now.getYear();
var month= now.getMonth()+1;
if (month<10)
month = "0" + month;
var days = now.getDate();
if (days<10)
days = "0" +days;
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M. " : " A.M. "
timeValue += "版权所有,不得翻录,违者必究";
window.status = year+"-"+month+"-"+days+" "+timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
</script>
<script language="javascript">
startclock();
</script>
shaopin 2003-05-22
  • 打赏
  • 举报
回复
<script>
function scroll()
{
dt=new Date();
sec=dt.getSeconds();
hr=dt.getHours();
ampm="A.M.";
smin=dt.getMinutes();
if (hr >=12) ampm="P.M.";
if (hr > 12) hr -=12;
if (smin <= 9) smin = "0"+smin;
if (sec <= 9) sec = "0"+sec;
if (hr <= 9) hr = "0"+hr;
var scroller="当前时间:"+hr+":"+smin+":"+sec+" "+ampm;
var timeout=setTimeout("scroll()", 1000);
clock.innerText=scroller;
}
</script>
<table><tr><td id=clock>
<script>scroll()</script>
住楼上的老丁 2003-05-22
  • 打赏
  • 举报
回复
谢谢大家的帮助,我的要求很简单,所以决定用shappin的代码。现在屡行我的承诺。
qiangliu666 2003-05-21
  • 打赏
  • 举报
回复
说明一下 applet小程序:
类文件Clock.class于html文件放在同一目录下。


qiangliu666 2003-05-21
  • 打赏
  • 举报
回复
//file name:Clock.java

import java.awt.*;

import java.util.Date;

public class Clock extends java.applet.Applet implements Runnable{

Thread clockThread;

public void start(){ // 鍦ˋpplet鐨剆tart鏂规硶涓垱寤哄苟鍚姩绾跨▼

if(clockThread==null){

clockThread=new Thread(this,"Clock");

clockThread.start(); // 鍚姩

}

}

public void run(){

while(clockThread!=null){

repaint();

try{

clockThread.sleep(1000);

}

catch(Exception e){}

}

}

public void paint(Graphics g){ // 璋冪敤drawString鏂规硶鐢诲嚭鏃躲€佸垎銆佺

Font f=new Font("TimesRoman",Font.BOLD,24);

g.setFont(f);

Date now=new Date();

g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),20,40);

}

public void stop(){ // 鍦ˋpplet鐨剆top鏂规硶涓娇绾跨▼娑堜骸

clockThread=null; // 涔熷彲鐢╟lockThread.stop();

}

}

HTML鏂囦欢锛?
<html>

<body>

<applet code="Clock.class" WIDTH=200 HEIGHT=70>

</applet>

</body>

</htmp>

wellsoon 2003-05-21
  • 打赏
  • 举报
回复
javascript的:

<!-- Time-->
<html>
<head>
<title>Time</title>
<style>
body { border: 0; background-color: buttonface; color: black; margin: 3px,0,0,0 }
.clocktxt { font-family: Arial; font-weight: normal; font-size: 8pt }
#btnsd { border: 2px groove white; background-color: buttonface; font-family: verdana; font-size: 9px }
</style>
<script language="JavaScript">
//Clock Script
var showclock;

function init(){
showdate()
showclock=true;
}

function showdate(){
//edit refresh rate here
var refreshrate=1000;

var Clock=new Date()
var hours=Clock.getHours()
var minutes=Clock.getMinutes()
var seconds=Clock.getSeconds()

var dn="AM"
if (hours>12){
dn="PM"
hours=hours-12
}

if (hours==0) hours=12
if (minutes<=9) minutes= "0" + minutes
if (seconds<=9) seconds= "0" + seconds

//edit format here
format = hours+":"+minutes+":"+seconds+" "+dn;

Time.innerHTML=format;

if (showclock==false) Time.innerHTML="<input type='button' value='Sh.time' id='btnsd' title='Show time'>"
else
setTimeout("showdate()",refreshrate)
}
</script>
</head>
<body scroll="no" onLoad="init()">
<center>
<font class="clocktxt"> <span id="Time" style="position:center;"></span></font>
<h1>test text!!!</h1>
</body>
</html>

81,090

社区成员

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

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