//======================================================================
//函数名称:
//功能说明:构造函数
//输入参数:控件ID
//输出参数:
//======================================================================
function CaClock(spanID){
//this._spanID = spanID;
this._intYear;
this._intMonth;
this._intDay;
this._intHours;
this._intMinutes;
this._intSeconds;
this._falg="true";
this.dateString;
this.timeString;
this.weekString;
}
//========================================================================
//函数名称:
//功能说明:设置时间秒加1
//输入参数:
//输出参数:
//========================================================================
CaClock.prototype.increaseSecond=function(){
this._intSeconds+=1;
this.ComputeDateTime();
if(this._intMonth<10){
month = "0"+ this._intMonth+"-"
}else{
month = this._intMonth+"-";
}
if(this._intDay<10){
day = "0"+this._intDay+" ";
}else{
day = this._intDay+" ";
}
if (this._intHours < 10) {
hours = "0"+this._intHours + ":";
} else {
hours = this._intHours + ":";
}
if (this._intMinutes < 10) {
minutes = "0"+this._intMinutes+":";
} else {
minutes = this._intMinutes+":";
}
if (this._intSeconds < 10) {
seconds = "0"+this._intSeconds;
} else {
seconds = this._intSeconds;
}
if(this._intDay<10){
day = "0"+this._intDay+" ";
}else{
day = this._intDay+" ";
}
year = this._intYear+"-";
this.dateString = year+month+day;
this.timeString = hours+minutes+seconds;
var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var dates=this.dateString.split("-");
var da = new Date(dates[0],dates[1]-1,dates[2]);
//alert(da.getYear()+"-"+da.getMonth()+"-"+da.getDate()+"星期"+da.getDay());
var dayOfWeek = da.getDay();
//alert(dayOfWeek);
this.weekString = days[dayOfWeek];
//if(this._falg=="true")
document.getElementById("date").innerHTML=this.dateString+this.timeString+" "+this.weekString;
window.setTimeout("C.increaseSecond();", 1000);
}
//========================================================================
//函数名称:
//功能说明:给时间进位
//输入参数:
//输出参数:输出到Span标签
CaClock.prototype.ComputeDateTime=function(){
if(this._intSeconds==60){
this._intSeconds=0;
this._intMinutes+=1;
}
if(this._intMinutes==60){
this._intMinutes=0;
this._intHours+=1;
}
if(this._intHours==24){
this._intHours=0;
this._intDay+=1;
}
if(this.judgeMonth()=="February"){
//判断润年,润年2月为28天
if(this.judgeYear()){
if(this._intDay==29){
this._intDay=1;
this._intMonth+=1;
}
}else{
if(this._intDay==30){
this._intDay=1;
this._intMonth+=1;
}
}
}
if(this.judgeMonth()=="bigMonth"){
if(this._intDay==32){
this._intDay=1;
this._intMonth+=1;
}
}
if(this.judgeMonth()=="samllMonth"){
if(this._intDay==31){
this._intDay=1;
this._intMonth+=1;
}
if(this._intDay>30){
this._intDay=1;
this._intMonth+=1;
}
}
if(this._intMonth==13){
this._intMonth=1;
this._intYear+=1;
}
}
//========================================================================
//函数名称:
//功能说明:判断年号是润年,平年
//输入参数:
//输出参数:润年(true),平年(false);
//========================================================================
CaClock.prototype.judgeYear=function(){
if((this._intYear%4==0 && this._intYear%100!=0)||(this._intYear%100==0&&this._intYear%400==0)){
return true;
}else{
return false;
}
}
//========================================================================
//函数名称:
//功能说明:判断月份大小 ,因2月特殊,所以单独判断
//输入参数:
//输出参数:大月(bigMonth),小月(samllMonth),2月(February)
//========================================================================
CaClock.prototype.judgeMonth=function(){
if(this._intMonth==1||this._intMonth==3||this._intMonth==5||this._intMonth==7||this._intMonth==8||this._intMonth==10||this._intMonth==12){
return "bigMonth";
}
if(this._intMonth==4||this._intMonth==6||this._intMonth==9||this._intMonth==11){
return "samllMonth";
}
if(this._intMonth==2){
return "February";
}
}
//========================================================================
//函数名称:
//功能说明:设置初始值
//输入参数:YYYY-MM-DD HH:MM:SS
//输出参数:
//========================================================================
CaClock.prototype.setInitValue=function(SDateTime){
var strDateTime = SDateTime.split(" ");
var SDate = strDateTime[0];
var STime = strDateTime[1];
var strSplitD = SDate.split("-");
var strSplitT = STime.split(":");
this._intYear = strSplitD[0]-0;
this._intMonth = strSplitD[1]-0;//月加1
this._intDay = strSplitD[2]-0;
this._intHours = strSplitT[0]-0;
this._intMinutes = strSplitT[1]-0;
this._intSeconds = strSplitT[2]-0;
}
var C = new CaClock("t");
function Start(){
//C. setCurrentTime();
C.increaseSecond();
}
function shows(){
var t=document.getElementById("times").value;
var d=document.getElementById("dates").value.toString();
var timess=""+d+" "+t+"";
C.setInitValue(timess);
Start();
}
//函数名称:
//功能说明:构造函数
//输入参数:控件ID
//输出参数:
//======================================================================
function CaClock(spanID){
//this._spanID = spanID;
this._intYear;
this._intMonth;
this._intDay;
this._intHours;
this._intMinutes;
this._intSeconds;
this._falg="true";
this.dateString;
this.timeString;
this.weekString;
}
//========================================================================
//函数名称:
//功能说明:设置时间秒加1
//输入参数:
//输出参数:
//========================================================================
CaClock.prototype.increaseSecond=function(){
this._intSeconds+=1;
this.ComputeDateTime();
if(this._intMonth<10){
month = "0"+ this._intMonth+"-"
}else{
month = this._intMonth+"-";
}
if(this._intDay<10){
day = "0"+this._intDay+" ";
}else{
day = this._intDay+" ";
}
if (this._intHours < 10) {
hours = "0"+this._intHours + ":";
} else {
hours = this._intHours + ":";
}
if (this._intMinutes < 10) {
minutes = "0"+this._intMinutes+":";
} else {
minutes = this._intMinutes+":";
}
if (this._intSeconds < 10) {
seconds = "0"+this._intSeconds;
} else {
seconds = this._intSeconds;
}
if(this._intDay<10){
day = "0"+this._intDay+" ";
}else{
day = this._intDay+" ";
}
year = this._intYear+"-";
this.dateString = year+month+day;
this.timeString = hours+minutes+seconds;
var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var dates=this.dateString.split("-");
var da = new Date(dates[0],dates[1]-1,dates[2]);
//alert(da.getYear()+"-"+da.getMonth()+"-"+da.getDate()+"星期"+da.getDay());
var dayOfWeek = da.getDay();
//alert(dayOfWeek);
this.weekString = days[dayOfWeek];
//if(this._falg=="true")
document.getElementById("date").innerHTML=this.dateString+this.timeString+" "+this.weekString;
window.setTimeout("C.increaseSecond();", 1000);
}
//========================================================================
//函数名称:
//功能说明:给时间进位
//输入参数:
//输出参数:输出到Span标签
CaClock.prototype.ComputeDateTime=function(){
if(this._intSeconds==60){
this._intSeconds=0;
this._intMinutes+=1;
}
if(this._intMinutes==60){
this._intMinutes=0;
this._intHours+=1;
}
if(this._intHours==24){
this._intHours=0;
this._intDay+=1;
}
if(this.judgeMonth()=="February"){
//判断润年,润年2月为28天
if(this.judgeYear()){
if(this._intDay==29){
this._intDay=1;
this._intMonth+=1;
}
}else{
if(this._intDay==30){
this._intDay=1;
this._intMonth+=1;
}
}
}
if(this.judgeMonth()=="bigMonth"){
if(this._intDay==32){
this._intDay=1;
this._intMonth+=1;
}
}
if(this.judgeMonth()=="samllMonth"){
if(this._intDay==31){
this._intDay=1;
this._intMonth+=1;
}
if(this._intDay>30){
this._intDay=1;
this._intMonth+=1;
}
}
if(this._intMonth==13){
this._intMonth=1;
this._intYear+=1;
}
}
//========================================================================
//函数名称:
//功能说明:判断年号是润年,平年
//输入参数:
//输出参数:润年(true),平年(false);
//========================================================================
CaClock.prototype.judgeYear=function(){
if((this._intYear%4==0 && this._intYear%100!=0)||(this._intYear%100==0&&this._intYear%400==0)){
return true;
}else{
return false;
}
}
//========================================================================
//函数名称:
//功能说明:判断月份大小 ,因2月特殊,所以单独判断
//输入参数:
//输出参数:大月(bigMonth),小月(samllMonth),2月(February)
//========================================================================
CaClock.prototype.judgeMonth=function(){
if(this._intMonth==1||this._intMonth==3||this._intMonth==5||this._intMonth==7||this._intMonth==8||this._intMonth==10||this._intMonth==12){
return "bigMonth";
}
if(this._intMonth==4||this._intMonth==6||this._intMonth==9||this._intMonth==11){
return "samllMonth";
}
if(this._intMonth==2){
return "February";
}
}
//========================================================================
//函数名称:
//功能说明:设置初始值
//输入参数:YYYY-MM-DD HH:MM:SS
//输出参数:
//========================================================================
CaClock.prototype.setInitValue=function(SDateTime){
var strDateTime = SDateTime.split(" ");
var SDate = strDateTime[0];
var STime = strDateTime[1];
var strSplitD = SDate.split("-");
var strSplitT = STime.split(":");
this._intYear = strSplitD[0]-0;
this._intMonth = strSplitD[1]-0;//月加1
this._intDay = strSplitD[2]-0;
this._intHours = strSplitT[0]-0;
this._intMinutes = strSplitT[1]-0;
this._intSeconds = strSplitT[2]-0;
}
var C = new CaClock("t");
function Start(){
//C. setCurrentTime();
C.increaseSecond();
}
function shows(){
var t=document.getElementById("times").value;
var d=document.getElementById("dates").value.toString();
var timess=""+d+" "+t+"";
C.setInitValue(timess);
Start();
}