定义一个时钟类-clock,包括三个int型的成员变量,分别表示时,分,秒,写两个构造方法,一个带参数,一个不带参数,有一个成员方法-show(),用于显示当前的时间
/*当前时间*/
window.setInterval('showTime()',1000);
function showTime(){
var enabled = 0;
today = new Date();
var day;
var date;
if(today.getDay()==0) day = "星期日"
if(today.getDay()==1) day = "星期一"
if(today.getDay()==2) day = "星期二"
if(today.getDay()==3) day = "星期三"
if(today.getDay()==4) day = "星期四"
if(today.getDay()==5) day = "星期五"
if(today.getDay()==6) day = "星期六"
date = (1900+today.getYear()) + "-" + (today.getMonth() + 1 ) + "-" + today.getDate() + " " +
" " +today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()+" "+day;
document.getElementById("time").innerHTML=date;
}
这是一个js文件,需要引入
package com.cbg;
public class clock {
private int hour;
private int min;
private int second;
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public int getMin() {
return min;
}
public void setMin(int min) {
this.min = min;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public clock(){
}
public clock(int hour, int min, int second) {
super();
this.hour = hour;
this.min = min;
this.second = second;
}
public void show(){
System.out.println("当前时间:"+hour+"时"+min+"分"+second+"秒");
}
}
望采纳。。