 
                    
                
         
    
    
    
	
	
	
	
		
 
 <script language="JavaScript">
<script language="JavaScript">
 <!--
<!--

 function PowerDate(timeString)
function PowerDate(timeString) {
{
 this.date=null;
this.date=null;
 if(timeString!="") this.date=new Date(timeString);
if(timeString!="") this.date=new Date(timeString);
 else this.date=new Date();
else this.date=new Date();
 this.isFmtZero=false;
this.isFmtZero=false;
 this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
 ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
  ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
 this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];

 this.getFullYear=function()
this.getFullYear=function() {
{
 return this.date.getFullYear();
return this.date.getFullYear();
 };
};

 this.getYear=function()
this.getYear=function() {
{
 return this.date.getYear();
return this.date.getYear();
 };
};

 this.getMonth=function()
this.getMonth=function() {
{
 var mm=this.date.getMonth()+1;
var mm=this.date.getMonth()+1;
 if(this.isFmtZero==true && mm<10)
if(this.isFmtZero==true && mm<10)
 return "0"+mm;
return "0"+mm;
 else return mm;
else return mm;
 };
};

 this.getDay=function()
this.getDay=function() {
{
 var dd=this.date.getDate();
var dd=this.date.getDate();
 if(this.isFmtZero==true && dd<10)
if(this.isFmtZero==true && dd<10)
 return "0"+dd;
return "0"+dd;
 else return dd;
else return dd;
 };
};

 this.getHour=function()
this.getHour=function() {
{
 var hh=this.date.getHours();
var hh=this.date.getHours();
 if(this.isFmtZero==true && hh<10)
if(this.isFmtZero==true && hh<10)
 return "0"+hh;
return "0"+hh;
 else return hh;
else return hh;
 };
};

 this.getMinute=function()
this.getMinute=function() {
{
 var mi=this.date.getMinutes();
var mi=this.date.getMinutes();
 if(this.isFmtZero==true && mi<10)
if(this.isFmtZero==true && mi<10)
 return "0"+mi;
return "0"+mi;
 else return mi;
else return mi;
 };
};

 this.getSecond=function()
this.getSecond=function() {
{
 var ss=this.date.getSeconds();
var ss=this.date.getSeconds();
 if(this.isFmtZero==true && ss<10)
if(this.isFmtZero==true && ss<10)
 return "0"+ss;
return "0"+ss;
 else return ss;
else return ss;
 };
};

 this.getMillisecond=function()
this.getMillisecond=function() {
{
 var ss=this.date.getMilliseconds();
var ss=this.date.getMilliseconds();
 if(this.isFmtZero==true && ss<10)
if(this.isFmtZero==true && ss<10)
 return "00"+ss;
return "00"+ss;
 else if(this.isFmtZero==true && ss<100)
else if(this.isFmtZero==true && ss<100)
 return "0"+ss;
return "0"+ss;
 else return ss;
else return ss;
 };
};

 this.getWeek=function()
this.getWeek=function() {
{
 return this.date.getDay();
return this.date.getDay();
 };
};

 this.setIsFmtZero=function(val)
this.setIsFmtZero=function(val) {
{
 this.isFmtZero=val;
this.isFmtZero=val;
 };
};

 /**//*
/**//*
 功能:根据输入表达式返回日期字符串
功能:根据输入表达式返回日期字符串
 参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
 isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
 */
*/

 this.getString=function(dateFmt)
this.getString=function(dateFmt) {
{
 if(typeof(dateFmt) != "string" )
if(typeof(dateFmt) != "string" )
 throw(new Error(-1, 'getString()方法需要字符串类型参数!'));
throw(new Error(-1, 'getString()方法需要字符串类型参数!'));
 var str=dateFmt;
var str=dateFmt;
 str=str.replace(/yy/g,this.getFullYear());
str=str.replace(/yy/g,this.getFullYear());
 str=str.replace(/YY/g,this.getYear());
str=str.replace(/YY/g,this.getYear());
 str=str.replace(/mm/g,this.getMonth());
str=str.replace(/mm/g,this.getMonth());
 str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
 str=str.replace(/dd/g,this.getDay());
str=str.replace(/dd/g,this.getDay());
 str=str.replace(/hh/g,this.getHour());
str=str.replace(/hh/g,this.getHour());
 str=str.replace(/mi/g,this.getMinute());
str=str.replace(/mi/g,this.getMinute());
 str=str.replace(/ss/g,this.getSecond());
str=str.replace(/ss/g,this.getSecond());
 str=str.replace(/ms/g,this.getMillisecond());
str=str.replace(/ms/g,this.getMillisecond());
 str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
 str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
 return str;
return str;
 };
};
 //返回N天前(后)的日期
//返回N天前(后)的日期
 //返回与另一日期之间的时间间隔
//返回与另一日期之间的时间间隔
 //
//
 }
}

 PowerDate.prototype.fmtWithZero= function()
PowerDate.prototype.fmtWithZero= function() {
{

 }
}
 var d= new PowerDate("");
var d= new PowerDate("");
 d.setIsFmtZero(true);
d.setIsFmtZero(true);
 alert(d.getString("yy-mm-dd hh:mi:ss.ms"));
alert(d.getString("yy-mm-dd hh:mi:ss.ms"));
 //-->
//-->
 </script>
</script>
 <body>
<body>
 </body>
</body>


 /**//*
/**//*
 ******************************************
******************************************
 日期函数扩充
日期函数扩充 
 ******************************************
******************************************
 */
*/



 /**//*
/**//*
 ===========================================
===========================================
 //转换成大写日期(中文)
//转换成大写日期(中文)
 ===========================================
===========================================
 */
*/
 Date.prototype.toCase = function()
Date.prototype.toCase = function()


 {
{
 var digits= new Array('零','一','二','三','四','五','六','七','八','九','十','十一','十二');
var digits= new Array('零','一','二','三','四','五','六','七','八','九','十','十一','十二');
 var unit= new Array('年','月','日','点','分','秒');
var unit= new Array('年','月','日','点','分','秒');

 var year= this.getYear() + "";
var year= this.getYear() + "";
 var index;
var index;
 var output="";
var output="";

 ////////得到年
////////得到年
 for (index=0;index<year.length;index++ )
for (index=0;index<year.length;index++ )


 {
{
 output += digits[parseInt(year.substr(index,1))];
output += digits[parseInt(year.substr(index,1))];
 }
}
 output +=unit[0];
output +=unit[0];

 ///////得到月
///////得到月
 output +=digits[this.getMonth()] + unit[1];
output +=digits[this.getMonth()] + unit[1];

 ///////得到日
///////得到日
 switch (parseInt(this.getDate() / 10))
switch (parseInt(this.getDate() / 10))


 {
{
 case 0:
case 0:
 output +=digits[this.getDate() % 10];
output +=digits[this.getDate() % 10];
 break;
break;
 case 1:
case 1:
 output +=digits[10] + ((this.getDate() % 10)>0?digits[(this.getDate() % 10)]:"");
output +=digits[10] + ((this.getDate() % 10)>0?digits[(this.getDate() % 10)]:"");
 break;
break;
 case 2:
case 2:
 case 3:
case 3:
 output +=digits[parseInt(this.getDate() / 10)] + digits[10]  + ((this.getDate() % 10)>0?digits[(this.getDate() % 10)]:"");
output +=digits[parseInt(this.getDate() / 10)] + digits[10]  + ((this.getDate() % 10)>0?digits[(this.getDate() % 10)]:"");
 default:
default:

 break;
break;
 }
}
 output +=unit[2];
output +=unit[2];

 ///////得到时
///////得到时
 switch (parseInt(this.getHours() / 10))
switch (parseInt(this.getHours() / 10))


 {
{
 case 0:
case 0:
 output +=digits[this.getHours() % 10];
output +=digits[this.getHours() % 10];
 break;
break;
 case 1:
case 1:
 output +=digits[10] + ((this.getHours() % 10)>0?digits[(this.getHours() % 10)]:"");
output +=digits[10] + ((this.getHours() % 10)>0?digits[(this.getHours() % 10)]:"");
 break;
break;
 case 2:
case 2:
 output +=digits[parseInt(this.getHours() / 10)] + digits[10] + ((this.getHours() % 10)>0?digits[(this.getHours() % 10)]:"");
output +=digits[parseInt(this.getHours() / 10)] + digits[10] + ((this.getHours() % 10)>0?digits[(this.getHours() % 10)]:"");
 break;
break;
 }
}
 output +=unit[3];
output +=unit[3];

 if(this.getMinutes()==0&&this.getSeconds()==0)
if(this.getMinutes()==0&&this.getSeconds()==0)


 {
{
 output +="整";
output +="整";
 return output;
return output;
 }
}

 ///////得到分
///////得到分
 switch (parseInt(this.getMinutes() / 10))
switch (parseInt(this.getMinutes() / 10))


 {
{
 case 0:
case 0:
 output +=digits[this.getMinutes() % 10];
output +=digits[this.getMinutes() % 10];
 break;
break;
 case 1:
case 1:
 output +=digits[10] + ((this.getMinutes() % 10)>0?digits[(this.getMinutes() % 10)]:"");
output +=digits[10] + ((this.getMinutes() % 10)>0?digits[(this.getMinutes() % 10)]:"");
 break;
break;
 case 2:
case 2:
 case 3:
case 3:
 case 4:
case 4:
 case 5:
case 5:
 output +=digits[parseInt(this.getMinutes() / 10)] + digits[10] + ((this.getMinutes() % 10)>0?digits[(this.getMinutes() % 10)]:"");
output +=digits[parseInt(this.getMinutes() / 10)] + digits[10] + ((this.getMinutes() % 10)>0?digits[(this.getMinutes() % 10)]:"");
 break;
break;
 }
}
 output +=unit[4];
output +=unit[4];

 if(this.getSeconds()==0)
if(this.getSeconds()==0)


 {
{
 output +="整";
output +="整";
 return output;
return output;
 }
}

 ///////得到秒
///////得到秒
 switch (parseInt(this.getSeconds() / 10))
switch (parseInt(this.getSeconds() / 10))


 {
{
 case 0:
case 0:
 output +=digits[this.getSeconds() % 10];
output +=digits[this.getSeconds() % 10];
 break;
break;
 case 1:
case 1:
 output +=digits[10] + ((this.getSeconds() % 10)>0?digits[(this.getSeconds() % 10)]:"");
output +=digits[10] + ((this.getSeconds() % 10)>0?digits[(this.getSeconds() % 10)]:"");
 break;
break;
 case 2:
case 2:
 case 3:
case 3:
 case 4:
case 4:
 case 5:
case 5:
 output +=digits[parseInt(this.getSeconds() / 10)] + digits[10] + ((this.getSeconds() % 10)>0?digits[(this.getSeconds() % 10)]:"");
output +=digits[parseInt(this.getSeconds() / 10)] + digits[10] + ((this.getSeconds() % 10)>0?digits[(this.getSeconds() % 10)]:"");
 break;
break;
 }
}
 output +=unit[5];
output +=unit[5];



 return output;
return output;
 }
}



 /**//*
/**//*
 ===========================================
===========================================
 //转换成农历
//转换成农历
 ===========================================
===========================================
 */
*/
 Date.prototype.toChinese = function()
Date.prototype.toChinese = function()


 {
{
 //暂缺
//暂缺
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //是否是闰年
//是否是闰年
 ===========================================
===========================================
 */
*/
 Date.prototype.isLeapYear = function()
Date.prototype.isLeapYear = function()


 {
{
 return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0)));
return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0)));
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //获得该月的天数
//获得该月的天数
 ===========================================
===========================================
 */
*/
 Date.prototype.getDayCountInMonth = function()
Date.prototype.getDayCountInMonth = function()


 {
{
 var mon = new Array(12);
var mon = new Array(12);

 mon[0] = 31; mon[1] = 28; mon[2] = 31; mon[3] = 30; mon[4]  = 31; mon[5]  = 30;
    mon[0] = 31; mon[1] = 28; mon[2] = 31; mon[3] = 30; mon[4]  = 31; mon[5]  = 30;
 mon[6] = 31; mon[7] = 31; mon[8] = 30; mon[9] = 31; mon[10] = 30; mon[11] = 31;
    mon[6] = 31; mon[7] = 31; mon[8] = 30; mon[9] = 31; mon[10] = 30; mon[11] = 31;

 if(0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0))&&this.getMonth()==2)
if(0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0))&&this.getMonth()==2)


 {
{
 return 29;
return 29;
 }
}
 else
else


 {
{
 return mon[this.getMonth()];
return mon[this.getMonth()];
 }
}
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //获得日期为星期几 (0为星期天)
//获得日期为星期几 (0为星期天)
 ===========================================
===========================================
 */
*/
 Date.prototype.weekOfDay = function()
Date.prototype.weekOfDay = function()


 {
{
 return this.getDay();
return this.getDay();
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //日期比较
//日期比较
 ===========================================
===========================================
 */
*/
 Date.prototype.Compare = function(objDate)
Date.prototype.Compare = function(objDate)


 {
{
 if(typeof(objDate)!="object" && objDate.constructor != Date)
if(typeof(objDate)!="object" && objDate.constructor != Date)


 {
{
 return -2;
return -2;
 }
}

 var d = this.getTime() - objDate.getTime();
var d = this.getTime() - objDate.getTime();

 if(d>0)
if(d>0)


 {
{
 return 1;
return 1;
 }
}
 else if(d==0)
else if(d==0) 


 {
{
 return 0;
return 0;
 }
}
 else
else


 {
{
 return -1;
return -1;
 }
}
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //格式化日期格式
//格式化日期格式
 ===========================================
===========================================
 */
*/
 Date.prototype.toString = function()
Date.prototype.toString = function()


 {
{
 if(arguments.length>0)
if(arguments.length>0)


 {
{
 var formatStr = arguments[0];
var formatStr = arguments[0];
 var str = formatStr;
var str = formatStr;

 str=str.replace(/yyyy|YYYY/,this.getFullYear());
str=str.replace(/yyyy|YYYY/,this.getFullYear());
 str=str.replace(/yy|YY/,(this.getFullYear() % 100)>9?(this.getFullYear() % 100).toString():"0" + (this.getFullYear() % 100));
str=str.replace(/yy|YY/,(this.getFullYear() % 100)>9?(this.getFullYear() % 100).toString():"0" + (this.getFullYear() % 100));

 str=str.replace(/MM/,this.getMonth()+1>9?(this.getMonth()+1).toString():"0" + (this.getMonth()+1));
str=str.replace(/MM/,this.getMonth()+1>9?(this.getMonth()+1).toString():"0" + (this.getMonth()+1));
 str=str.replace(/M/g,(this.getMonth()+1).toString());
str=str.replace(/M/g,(this.getMonth()+1).toString());

 str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():"0" + this.getDate());
str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():"0" + this.getDate());
 str=str.replace(/d|D/g,this.getDate());
str=str.replace(/d|D/g,this.getDate());

 str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():"0" + this.getHours());
str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():"0" + this.getHours());
 str=str.replace(/h|H/g,this.getHours());
str=str.replace(/h|H/g,this.getHours());

 str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():"0" + this.getMinutes());
str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():"0" + this.getMinutes());
 str=str.replace(/m/g,this.getMinutes());
str=str.replace(/m/g,this.getMinutes());

 str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():"0" + this.getSeconds());
str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():"0" + this.getSeconds());
 str=str.replace(/s|S/g,this.getSeconds());
str=str.replace(/s|S/g,this.getSeconds());

 return str;
return str;

 }
}
 else
else


 {
{
 return this.toLocaleString();
return this.toLocaleString();
 }
}
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //由字符串直接实例日期对象
//由字符串直接实例日期对象
 ===========================================
===========================================
 */
*/
 Date.prototype.instanceFromString = function(str)
Date.prototype.instanceFromString = function(str)


 {
{
 return new Date(str.replace(/-/g, "\/"));
return new Date(str.replace(/-/g, "\/"));
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //得到日期年月日等加数字后的日期
//得到日期年月日等加数字后的日期
 ===========================================
===========================================
 */
*/
 Date.prototype.dateAdd = function(interval,number)
Date.prototype.dateAdd = function(interval,number)


 {
{
 var date = this;
var date = this;

 switch(interval)
    switch(interval)

 
     {
{
 case "y" :
        case "y" : 
 date.setFullYear(date.getFullYear()+number);
            date.setFullYear(date.getFullYear()+number);
 return date;
            return date;

 case "q" :
        case "q" : 
 date.setMonth(date.getMonth()+number*3);
            date.setMonth(date.getMonth()+number*3);
 return date;
            return date;

 case "m" :
        case "m" : 
 date.setMonth(date.getMonth()+number);
            date.setMonth(date.getMonth()+number);
 return date;
            return date;

 case "w" :
        case "w" : 
 date.setDate(date.getDate()+number*7);
            date.setDate(date.getDate()+number*7);
 return date;
            return date;
 
        
 case "d" :
        case "d" : 
 date.setDate(date.getDate()+number);
            date.setDate(date.getDate()+number);
 return date;
            return date;

 case "h" :
        case "h" : 
 date.setHours(date.getHours()+number);
            date.setHours(date.getHours()+number);
 return date;
            return date;

 case "m" :
case "m" : 
 date.setMinutes(date.getMinutes()+number);
            date.setMinutes(date.getMinutes()+number);
 return date;
            return date;

 case "s" :
case "s" : 
 date.setSeconds(date.getSeconds()+number);
            date.setSeconds(date.getSeconds()+number);
 return date;
            return date;

 default :
        default : 
 date.setDate(d.getDate()+number);
            date.setDate(d.getDate()+number);
 return date;
            return date;
 }
    }
 }
}


 /**//*
/**//*
 ===========================================
===========================================
 //计算两日期相差的日期年月日等
//计算两日期相差的日期年月日等
 ===========================================
===========================================
 */
*/
 Date.prototype.dateDiff = function(interval,o)
Date.prototype.dateDiff = function(interval,o)


 {
{
 //判断o是否为日期对象
//判断o是否为日期对象
 if(o&&o.constructor==Date)
if(o&&o.constructor==Date)


 {
{
 //判断是否interval是否是字符串对象
//判断是否interval是否是字符串对象
 if (interval&&interval.constructor==String)
if (interval&&interval.constructor==String) 


 {
{

 var _start= this.getTime();
var _start= this.getTime();
 var _end= o.getTime();
var _end= o.getTime();

 var number= _end - _start;
var number= _end - _start;

 var iOut = -1;
var iOut = -1;

 
   
 switch (interval.charAt(0))
switch (interval.charAt(0))


 {
{
 case 'y':case 'Y'://year
case 'y':case 'Y'://year
 iOut =  o.getFullYear() - this.getFullYear();
iOut =  o.getFullYear() - this.getFullYear();
 break;
break;
 case 'm':case 'M'://month
case 'm':case 'M'://month
 iOut = (o.getFullYear() - this.getFullYear()) * 12 + (o.getMonth()-this.getMonth());
iOut = (o.getFullYear() - this.getFullYear()) * 12 + (o.getMonth()-this.getMonth());
 break;
break;
 case 'q':case 'Q'://quarter
case 'q':case 'Q'://quarter
 iOut = ((o.getFullYear() - this.getFullYear()) * 12 + (o.getMonth()-this.getMonth()))/3;
iOut = ((o.getFullYear() - this.getFullYear()) * 12 + (o.getMonth()-this.getMonth()))/3;
 break;
break;
 case 'd':case 'D'://day
case 'd':case 'D'://day
 iOut = parseInt(number / 86400000) ;
iOut = parseInt(number / 86400000) ;
 break;
break;
 case 'w':case 'W'://week
case 'w':case 'W'://week
 iOut = parseInt(number / 86400000/7) ;
iOut = parseInt(number / 86400000/7) ;
 break;
break;
 case 'h':case 'H'://hour
case 'h':case 'H'://hour
 iOut = parseInt(number / 3600000 ) ;
iOut = parseInt(number / 3600000 ) ;
 break;
break;
 case 'n':case 'N'://minute
case 'n':case 'N'://minute
 iOut = parseInt(number / 60000 ) ;
iOut = parseInt(number / 60000 ) ;
 break;
break;
 case 's': case 'S'://second
case 's': case 'S'://second
 iOut = parseInt(number / 1000 ) ;
iOut = parseInt(number / 1000 ) ;
 break;
break;
 case 't':case 'T'://microsecond
case 't':case 'T'://microsecond
 iOut = parseInt(number);
iOut = parseInt(number);
 break;
break;
 default:
default:
 iOut = -1;
iOut = -1;
 }
}

 return iOut;
return iOut;
 }
}
 }
}

 return -1
return -1

 }
}



 /**//*
/**//*
 ===========================================
===========================================
 //得到日期的组成部分
//得到日期的组成部分
 ===========================================
===========================================
 */
*/
 Date.prototype.datePart = function(interval)
Date.prototype.datePart = function(interval)


 {
{

 if(interval==null)
if(interval==null)


 {
{
 return -1;
return -1;
 }
}

 if(/^(yy|yyyy)$/.test(interval))
if(/^(yy|yyyy)$/.test(interval))


 {
{
 return this.getFullYear();
return this.getFullYear();
 }
}

 if(/^(qq|q)$/.test(interval))
if(/^(qq|q)$/.test(interval))


 {
{
 return Math.ceil((this.getMonth()+1) / 4);
return Math.ceil((this.getMonth()+1) / 4);
 }
}

 if(/^(mm|m)$/.test(interval))
if(/^(mm|m)$/.test(interval))


 {
{
 return this.getMonth();
return this.getMonth();
 }
}

 if(/^(dd|d)$/.test(interval))
if(/^(dd|d)$/.test(interval))


 {
{
 return this.getDate();
return this.getDate();
 }
}

 if(/^(dw)$/.test(interval))
if(/^(dw)$/.test(interval))


 {
{
 return this.getDay();
return this.getDay();
 }
}

 if(/^(hh|h)$/.test(interval))
if(/^(hh|h)$/.test(interval))


 {
{
 return this.getHours();
return this.getHours();
 }
}

 if(/^(mi|n)$/.test(interval))
if(/^(mi|n)$/.test(interval))


 {
{
 return this.getMinutes();
return this.getMinutes();
 }
}

 if(/^(ss|s)$/.test(interval))
if(/^(ss|s)$/.test(interval))


 {
{
 return this.getSeconds();
return this.getSeconds();
 }
}

 if(/^(ms)$/.test(interval))
if(/^(ms)$/.test(interval))


 {
{
 return this.getMilliseconds();
return this.getMilliseconds();
 }
}

 //缺少日期的第几周,第几天
//缺少日期的第几周,第几天

 return -1;
return -1;
 }
}

 **
**
 *功能:返回格式化后的日期字符串
*功能:返回格式化后的日期字符串
 *参数:formatStr为格式字符串,其中表示形式如下列表
*参数:formatStr为格式字符串,其中表示形式如下列表
 *“ddd”-汉字星期几
*“ddd”-汉字星期几
 *“yyyy”-四位数年份
*“yyyy”-四位数年份
 *“MM”-两位数月份
*“MM”-两位数月份
 *“dd”-两位数日期
*“dd”-两位数日期
 *“hh”-两位数小时
*“hh”-两位数小时
 *“mm”-两位数分钟
*“mm”-两位数分钟
 *“ss”-两位数秒数
*“ss”-两位数秒数
 *“y”-年份
*“y”-年份
 *“M”-月份
*“M”-月份
 *“d”-日期
*“d”-日期
 *“h”-小时
*“h”-小时
 *“m”-分钟
*“m”-分钟
 *“s”-秒数
*“s”-秒数
 */
*/

 Date.prototype.format = function (formatStr)
Date.prototype.format = function (formatStr)  {
{
 var WEEK = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var WEEK = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
 var s = formatStr;
var s = formatStr;


 s = s.replace(/d
s = s.replace(/d {3}/g, WEEK[this.getDay()]);
{3}/g, WEEK[this.getDay()]);


 s = s.replace(/y
s = s.replace(/y {4}/g, this.getFullYear());
{4}/g, this.getFullYear());

 s = s.replace(/M
s = s.replace(/M {2}/g, (this.getMonth()+1)<10 ? "0"+(this.getMonth()+1) : (this.getMonth()+1));
{2}/g, (this.getMonth()+1)<10 ? "0"+(this.getMonth()+1) : (this.getMonth()+1));

 s = s.replace(/d
s = s.replace(/d {2}/g, this.getDate()<10 ? "0"+this.getDate() : this.getDate());
{2}/g, this.getDate()<10 ? "0"+this.getDate() : this.getDate());

 s = s.replace(/h
s = s.replace(/h {2}/g, this.getHours()<10 ? "0"+this.getHours() : this.getHours());
{2}/g, this.getHours()<10 ? "0"+this.getHours() : this.getHours());

 s = s.replace(/m
s = s.replace(/m {2}/g, this.getMinutes()<10 ? "0"+this.getMinutes() : this.getMinutes());
{2}/g, this.getMinutes()<10 ? "0"+this.getMinutes() : this.getMinutes());

 s = s.replace(/s
s = s.replace(/s {2}/g, this.getSeconds()<10 ? "0"+this.getSeconds() : this.getSeconds());
{2}/g, this.getSeconds()<10 ? "0"+this.getSeconds() : this.getSeconds());


 s = s.replace(/y
s = s.replace(/y {1}/g, this.getFullYear());
{1}/g, this.getFullYear());

 s = s.replace(/M
s = s.replace(/M {1}/g, this.getMonth() + 1);
{1}/g, this.getMonth() + 1);

 s = s.replace(/d
s = s.replace(/d {1}/g, this.getDate());
{1}/g, this.getDate());

 s = s.replace(/h
s = s.replace(/h {1}/g, this.getHours());
{1}/g, this.getHours());

 s = s.replace(/m
s = s.replace(/m {1}/g, this.getMinutes());
{1}/g, this.getMinutes());

 s = s.replace(/s
s = s.replace(/s {1}/g, this.getSeconds());
{1}/g, this.getSeconds());

 return(s);
return(s);
 }
}


 zhaoxiaoyang(梅雪香@深圳)
 zhaoxiaoyang(梅雪香@深圳) 
 整理完毕,发出来大家测测,有意见和建议快提,我好快改
整理完毕,发出来大家测测,有意见和建议快提,我好快改

 另:计算两个日期的差的功能,我不清楚该如何设计.请大家发表高论!
另:计算两个日期的差的功能,我不清楚该如何设计.请大家发表高论!

 <script language="JavaScript">
<script language="JavaScript">
 <!--
<!--

 function PowerDate(timeString)
function PowerDate(timeString) {
{
 this.date=null;
this.date=null;
 if(timeString!="") this.date=new Date(timeString);
if(timeString!="") this.date=new Date(timeString);
 else this.date=new Date();
else this.date=new Date();
 this.isFmtZero=false;
this.isFmtZero=false;
 this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
 ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
  ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
 this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];

 this.getFullYear=function()
this.getFullYear=function() {
{
 return this.date.getFullYear();
return this.date.getFullYear();
 };
};

 this.getYear=function()
this.getYear=function() {
{
 return this.date.getYear();
return this.date.getYear();
 };
};

 this.getMonth=function()
this.getMonth=function() {
{
 var mm=this.date.getMonth()+1;
var mm=this.date.getMonth()+1;
 if(this.isFmtZero==true && mm<10)
if(this.isFmtZero==true && mm<10)
 return "0"+mm;
return "0"+mm;
 else return mm;
else return mm;
 };
};

 this.getDay=function()
this.getDay=function() {
{
 var dd=this.date.getDate();
var dd=this.date.getDate();
 if(this.isFmtZero==true && dd<10)
if(this.isFmtZero==true && dd<10)
 return "0"+dd;
return "0"+dd;
 else return dd;
else return dd;
 };
};

 this.getHour=function()
this.getHour=function() {
{
 var hh=this.date.getHours();
var hh=this.date.getHours();
 if(this.isFmtZero==true && hh<10)
if(this.isFmtZero==true && hh<10)
 return "0"+hh;
return "0"+hh;
 else return hh;
else return hh;
 };
};

 this.getMinute=function()
this.getMinute=function() {
{
 var mi=this.date.getMinutes();
var mi=this.date.getMinutes();
 if(this.isFmtZero==true && mi<10)
if(this.isFmtZero==true && mi<10)
 return "0"+mi;
return "0"+mi;
 else return mi;
else return mi;
 };
};

 this.getSecond=function()
this.getSecond=function() {
{
 var ss=this.date.getSeconds();
var ss=this.date.getSeconds();
 if(this.isFmtZero==true && ss<10)
if(this.isFmtZero==true && ss<10)
 return "0"+ss;
return "0"+ss;
 else return ss;
else return ss;
 };
};

 this.getMillisecond=function()
this.getMillisecond=function() {
{
 var ss=this.date.getMilliseconds();
var ss=this.date.getMilliseconds();
 if(this.isFmtZero==true && ss<10)
if(this.isFmtZero==true && ss<10)
 return "00"+ss;
return "00"+ss;
 else if(this.isFmtZero==true && ss<100)
else if(this.isFmtZero==true && ss<100)
 return "0"+ss;
return "0"+ss;
 else return ss;
else return ss;
 };
};

 this.getWeek=function()
this.getWeek=function() {
{
 return this.date.getDay();
return this.date.getDay();
 };
};

 this.setIsFmtZero=function(val)
this.setIsFmtZero=function(val) {
{
 this.isFmtZero=val;
this.isFmtZero=val;
 };
};

 /**//*
/**//*
 功能:根据输入表达式返回日期字符串
功能:根据输入表达式返回日期字符串
 参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
 isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
 */
*/

 this.getString=function(dateFmt)
this.getString=function(dateFmt) {
{
 if(typeof(dateFmt) != "string" )
if(typeof(dateFmt) != "string" )
 throw (new Error(-1, 'getString()方法需要字符串类型参数!'));
throw (new Error(-1, 'getString()方法需要字符串类型参数!'));
 var str=dateFmt;
var str=dateFmt;
 str=str.replace(/yy/g,this.getFullYear());
str=str.replace(/yy/g,this.getFullYear());
 str=str.replace(/YY/g,this.getYear());
str=str.replace(/YY/g,this.getYear());
 str=str.replace(/mm/g,this.getMonth());
str=str.replace(/mm/g,this.getMonth());
 str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
 str=str.replace(/dd/g,this.getDay());
str=str.replace(/dd/g,this.getDay());
 str=str.replace(/hh/g,this.getHour());
str=str.replace(/hh/g,this.getHour());
 str=str.replace(/mi/g,this.getMinute());
str=str.replace(/mi/g,this.getMinute());
 str=str.replace(/ss/g,this.getSecond());
str=str.replace(/ss/g,this.getSecond());
 str=str.replace(/ms/g,this.getMillisecond());
str=str.replace(/ms/g,this.getMillisecond());
 str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
 str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
 return str;
return str;
 };
};


 /**//* 名称 : dateAfterDays
/**//* 名称 : dateAfterDays
 * 功能 : 返回与某日期相距N天(N个24小时)的日期
 * 功能 : 返回与某日期相距N天(N个24小时)的日期
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 返回 : 新的日期
 * 返回 : 新的日期
 * 方法 : powerDate.dateAfterDays(num);
 * 方法 : powerDate.dateAfterDays(num);
 */
 */

 this.dateAfterDays=function(num)
this.dateAfterDays=function(num) {
{
 if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
 var dd = this.date.valueOf();
var dd = this.date.valueOf();
 dd += num*24*3600*1000;
dd += num*24*3600*1000;
 this.date=new Date(dd);
this.date=new Date(dd);
 return this;
return this;
 };
};


 /**//* 名称 : dateAfterSeconds
/**//* 名称 : dateAfterSeconds
 * 功能 : 返回与某日期相距N秒的日期
 * 功能 : 返回与某日期相距N秒的日期
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 返回 : 新的日期
 * 返回 : 新的日期
 * 方法 : powerDate.dateAfterDays(num);
 * 方法 : powerDate.dateAfterDays(num);
 */
 */

 this.dateAfterSeconds=function(num)
this.dateAfterSeconds=function(num) {
{
 if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
 var dd = this.date.valueOf();
var dd = this.date.valueOf();
 dd += num*1000;
dd += num*1000;
 this.date=new Date(dd);
this.date=new Date(dd);
 return this;
return this;
 };
};

 //判断是否是闰年
//判断是否是闰年

 this.isLeapYear = function ()
this.isLeapYear = function () {
{
 var year = this.getFullYear();
var year = this.getFullYear();
 return (0==year%4 && ((year % 100 != 0)||(year % 400 == 0)));
return (0==year%4 && ((year % 100 != 0)||(year % 400 == 0)));
 };
};

 //返回该月天数
//返回该月天数

 this.getDaysOfMonth = function ()
this.getDaysOfMonth = function () {
{
 return (new Date(this.getFullYear(),this.getMonth(),0)).getDate();
return (new Date(this.getFullYear(),this.getMonth(),0)).getDate();
 };
};

 //转换成大写日期(中文)
//转换成大写日期(中文)

 this.getChinaDate =  function()
this.getChinaDate =  function() {
{
 var year = this.getFullYear().toString();
var year = this.getFullYear().toString();
 var month= this.getMonth().toString();
var month= this.getMonth().toString();
 var day = this.getDay().toString();
var day = this.getDay().toString();
 var arrNum = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];
var arrNum = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];
 var strTmp="";
var strTmp="";

 for(var i=0,j=year.length;i<j;i++)
for(var i=0,j=year.length;i<j;i++) {
{
 strTmp += arrNum[year.charAt(i)];
strTmp += arrNum[year.charAt(i)];
 }
}
 strTmp += "年";
strTmp += "年";
 strTmp += arrNum[month]+"月";
strTmp += arrNum[month]+"月";
 if(day<10)
if(day<10)
 strTmp += arrNum[day];
strTmp += arrNum[day];
 else if (day <20)
else if (day <20)
 strTmp += "十"+arrNum[day-10];
strTmp += "十"+arrNum[day-10];
 else if (day <30 )
else if (day <30 )
 strTmp += "二十"+arrNum[day-20];
strTmp += "二十"+arrNum[day-20];
 else
else 
 strTmp += "三十"+arrNum[day-30];
strTmp += "三十"+arrNum[day-30];
 strTmp += "日";
strTmp += "日";
 return strTmp;
return strTmp;
 };
};

 //日期比较函数,如大于参数:1,相等:0 不等: -1
//日期比较函数,如大于参数:1,相等:0 不等: -1

 this.dateCompare = function(dat)
this.dateCompare = function(dat) {
{

 if(typeof(dat)=="string")
if(typeof(dat)=="string") {
{
 if(dat!="") dat=new Date(timeString);
if(dat!="") dat=new Date(timeString);
 else dat=new Date();
else dat=new Date();
 }
}
 if(typeof(dat)!="object" || dat.constructor != Date)
if(typeof(dat)!="object" || dat.constructor != Date)


 {
{
 throw new Error(-2,"dateCompare的参数为日期类型或者可直接转化为日期类型的字符串!");
throw new Error(-2,"dateCompare的参数为日期类型或者可直接转化为日期类型的字符串!");
 }
}
 var d = this.date.getTime() - dat.getTime();
var d = this.date.getTime() - dat.getTime();
 return d>0?1:(d==0?0:-1);
return d>0?1:(d==0?0:-1);
 }
}
 }
}
 var d= new PowerDate("");
var d= new PowerDate("");
 d.setIsFmtZero(true);
d.setIsFmtZero(true);

 alert(d.getString("yy-mm-dd hh:mi:ss.ms"));
alert(d.getString("yy-mm-dd hh:mi:ss.ms"));

 //-->
//-->
 </script>
</script>
 <body>
<body>
 </body>
</body>



 又改写了一下,可以用所有初始化Date对象的方法来初始化PowerDate对象了,而且可以是更不符合要求的字符串如: new PowerDate("  2005@#@#8----22    ");也一样可以成功初始化,只是一定要包含三个数值.
又改写了一下,可以用所有初始化Date对象的方法来初始化PowerDate对象了,而且可以是更不符合要求的字符串如: new PowerDate("  2005@#@#8----22    ");也一样可以成功初始化,只是一定要包含三个数值.
 农历的算法太长了,而且在开发中也很少应用,所以暂不加到该类中来.
农历的算法太长了,而且在开发中也很少应用,所以暂不加到该类中来.
 新代码如下:
新代码如下:

 <script language="JavaScript">
<script language="JavaScript">
 <!--
<!--

 function PowerDate()
function PowerDate() {
{
 //日期对象
//日期对象
 this.date=null;
this.date=null;
 //格式化时是否加零补位标志
//格式化时是否加零补位标志
 this.isFmtZero=false;
this.isFmtZero=false;
 this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
this.weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
 ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
  ["SUN","MON","TUR","WED","THU","FRI","SAT"]];
 this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
this.monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
 //初始化日期对象
//初始化日期对象

 switch(arguments.length)
switch(arguments.length) {
{
 case 0:
case 0:
 this.date = new Date();
this.date = new Date();
 break;
break;
 case 1:
case 1: 

 var reg = /^(\d
var reg = /^(\d {2,4})\D+(\d
{2,4})\D+(\d {1,2})\D+(\d
{1,2})\D+(\d {1,2})$/;
{1,2})$/;
 var str = arguments[0].replace(/\s/,"");
var str = arguments[0].replace(/\s/,"");
 str = str.replace(reg,"$1/$2/$3");
str = str.replace(reg,"$1/$2/$3");
 this.date = new Date(str);
this.date = new Date(str);
 break;
break;
 case 3:
case 3: 
 this.date = new Date(arguments[0],arguments[1]-1,arguments[2]);
this.date = new Date(arguments[0],arguments[1]-1,arguments[2]);
 break;
break;
 case 6:
case 6: 
 this.date = new Date(arguments[0],arguments[1]-1,arguments[2],arguments[3],arguments[4],arguments[5]);
this.date = new Date(arguments[0],arguments[1]-1,arguments[2],arguments[3],arguments[4],arguments[5]);
 break;
break;
 case 7:
case 7: 
 this.date = new Date(arguments[0],arguments[1]-1,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);
this.date = new Date(arguments[0],arguments[1]-1,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);
 break;
break;
 default: this.date = new Date("1970/1/1"); break;
default: this.date = new Date("1970/1/1"); break;
 }
}
 //初始化失败处理
//初始化失败处理
 if(typeof(this.date) != "object" || !(/Date/.test(this.date.constructor)))
if(typeof(this.date) != "object" || !(/Date/.test(this.date.constructor)))
 throw (new Error(-1, '构造PowerDate方法失败,检查输入参数!'));
throw (new Error(-1, '构造PowerDate方法失败,检查输入参数!'));


 this.getDate = function ()
this.getDate = function () {
{
 return this.date;
return this.date;
 }
}

 this.getFullYear=function()
this.getFullYear=function() {
{
 return this.date.getFullYear();
return this.date.getFullYear();
 };
};

 this.getYear=function()
this.getYear=function() {
{
 return this.date.getYear();
return this.date.getYear();
 };
};

 this.getMonth=function()
this.getMonth=function() {
{
 return this.frmWithZero(this.date.getMonth()+1);
return this.frmWithZero(this.date.getMonth()+1);
 };
};

 this.getDay=function()
this.getDay=function() {
{
 return this.frmWithZero(this.date.getDate());
return this.frmWithZero(this.date.getDate());
 };
};

 this.getHour=function()
this.getHour=function() {
{
 return this.frmWithZero(this.date.getHours());
return this.frmWithZero(this.date.getHours());
 };
};

 this.getMinute=function()
this.getMinute=function() {
{
 return this.frmWithZero(this.date.getMinutes());
return this.frmWithZero(this.date.getMinutes());
 };
};

 this.getSecond=function()
this.getSecond=function() {
{
 return this.frmWithZero(this.date.getSeconds());
return this.frmWithZero(this.date.getSeconds());
 };
};

 this.getMillisecond=function()
this.getMillisecond=function() {
{
 var ss=this.date.getMilliseconds();
var ss=this.date.getMilliseconds();
 if(this.isFmtZero==true && ss<10)
if(this.isFmtZero==true && ss<10)
 return "00"+ss;
return "00"+ss;
 else if(this.isFmtZero==true && ss<100)
else if(this.isFmtZero==true && ss<100)
 return "0"+ss;
return "0"+ss;
 else return ss;
else return ss;
 };
};

 this.getWeek=function()
this.getWeek=function() {
{
 return this.date.getDay();
return this.date.getDay();
 };
};

 this.setIsFmtZero=function(val)
this.setIsFmtZero=function(val) {
{
 this.isFmtZero=val;
this.isFmtZero=val;
 };
};

 this.frmWithZero = function(num)
this.frmWithZero = function(num) {
{
 if(this.isFmtZero==true && num<10)
if(this.isFmtZero==true && num<10)
 return "0"+num;
return "0"+num;
 else return num;
else return num;
 }
}

 /**//*
/**//*
 功能:根据输入表达式返回日期字符串
功能:根据输入表达式返回日期字符串
 参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
参数:dateFmt:字符串,由以下结构组成 yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
 isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
isFmtZero:布尔值,true:需要用0补位,false:不需要用0补位
 */
*/

 this.getString=function(dateFmt)
this.getString=function(dateFmt) {
{
 if(typeof(dateFmt) != "string" )
if(typeof(dateFmt) != "string" )
 throw (new Error(-1, 'getString()方法需要字符串类型参数!'));
throw (new Error(-1, 'getString()方法需要字符串类型参数!'));
 var str=dateFmt;
var str=dateFmt;
 str=str.replace(/yy/g,this.getFullYear());
str=str.replace(/yy/g,this.getFullYear());
 str=str.replace(/YY/g,this.getYear());
str=str.replace(/YY/g,this.getYear());
 str=str.replace(/mm/g,this.getMonth());
str=str.replace(/mm/g,this.getMonth());
 str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
str=str.replace(/MM/g,this.monthArr[this.getMonth()-1]);
 str=str.replace(/dd/g,this.getDay());
str=str.replace(/dd/g,this.getDay());
 str=str.replace(/hh/g,this.getHour());
str=str.replace(/hh/g,this.getHour());
 str=str.replace(/mi/g,this.getMinute());
str=str.replace(/mi/g,this.getMinute());
 str=str.replace(/ss/g,this.getSecond());
str=str.replace(/ss/g,this.getSecond());
 str=str.replace(/ms/g,this.getMillisecond());
str=str.replace(/ms/g,this.getMillisecond());
 str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
str=str.replace(/we/g,this.weekArr[0][this.getWeek()]);
 str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
str=str.replace(/WE/g,this.weekArr[1][this.getWeek()]);
 return str;
return str;
 };
};


 /**//* 功能 : 返回与某日期相距N天(N个24小时)的日期
/**//* 功能 : 返回与某日期相距N天(N个24小时)的日期
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 返回 : 新的PowerDate类型
 * 返回 : 新的PowerDate类型
 * 方法 : powerDate.dateAfterDays(num);
 * 方法 : powerDate.dateAfterDays(num);
 */
 */

 this.dateAfterDays=function(num)
this.dateAfterDays=function(num) {
{
 if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
 var dd = this.date.valueOf();
var dd = this.date.valueOf();
 dd += num*24*3600*1000;
dd += num*24*3600*1000;
 this.date=new Date(dd);
this.date=new Date(dd);
 return this;
return this;
 };
};


 /**//* 功能 : 返回与某日期相距N秒的日期
/**//* 功能 : 返回与某日期相距N秒的日期
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 参数 : num number类型 可以为正负整数或者浮点数
 * 返回 : 新的日期
 * 返回 : 新的日期
 * 方法 : powerDate.dateAfterDays(num);
 * 方法 : powerDate.dateAfterDays(num);
 */
 */

 this.dateAfterSeconds=function(num)
this.dateAfterSeconds=function(num) {
{
 if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num)参数为数值类型.");
 var dd = this.date.valueOf();
var dd = this.date.valueOf();
 dd += num*1000;
dd += num*1000;
 this.date=new Date(dd);
this.date=new Date(dd);
 return this;
return this;
 };
};

 //判断是否是闰年
//判断是否是闰年

 this.isLeapYear = function ()
this.isLeapYear = function () {
{
 var year = this.getFullYear();
var year = this.getFullYear();
 return (0==year%4 && ((year % 100 != 0)||(year % 400 == 0)));
return (0==year%4 && ((year % 100 != 0)||(year % 400 == 0)));
 };
};

 //返回该月天数
//返回该月天数

 this.getDaysOfMonth = function ()
this.getDaysOfMonth = function () {
{
 return (new Date(this.getFullYear(),this.getMonth(),0)).getDate();
return (new Date(this.getFullYear(),this.getMonth(),0)).getDate();
 };
};

 //转换成大写日期(中文)
//转换成大写日期(中文)

 this.getChinaDate =  function()
this.getChinaDate =  function() {
{
 var year = this.getFullYear();
var year = this.getFullYear();
 var month= this.getMonth();
var month= this.getMonth();
 var day = this.getDay();
var day = this.getDay();
 var arrNum = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];
var arrNum = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];
 var strTmp="";
var strTmp="";

 for(var i=0,j=year.length;i<j;i++)
for(var i=0,j=year.length;i<j;i++) {
{
 strTmp += arrNum[year.charAt(i)];
strTmp += arrNum[year.charAt(i)];
 }
}
 strTmp += "年";
strTmp += "年";
 strTmp += arrNum[month]+"月";
strTmp += arrNum[month]+"月";
 if(day<10)
if(day<10)
 strTmp += arrNum[day];
strTmp += arrNum[day];
 else if (day <20)
else if (day <20)
 strTmp += "十"+arrNum[day-10];
strTmp += "十"+arrNum[day-10];
 else if (day <30 )
else if (day <30 )
 strTmp += "二十"+arrNum[day-20];
strTmp += "二十"+arrNum[day-20];
 else
else 
 strTmp += "三十"+arrNum[day-30];
strTmp += "三十"+arrNum[day-30];
 strTmp += "日";
strTmp += "日";
 return strTmp;
return strTmp;
 };
};

 //日期比较函数,如大于参数:1,相等:0 不等: -1
//日期比较函数,如大于参数:1,相等:0 不等: -1

 this.dateCompare = function(dat)
this.dateCompare = function(dat) {
{

 if(typeof(dat)=="string")
if(typeof(dat)=="string") {
{
 if(dat!="") dat=new Date(timeString);
if(dat!="") dat=new Date(timeString);
 else dat=new Date();
else dat=new Date();
 }
}
 if(typeof(dat)!="object" || !(/Date/.test(this.date.constructor)))
if(typeof(dat)!="object" || !(/Date/.test(this.date.constructor)))


 {
{
 throw new Error(-2,"dateCompare的参数为日期类型或者可直接转化为日期类型的字符串!");
throw new Error(-2,"dateCompare的参数为日期类型或者可直接转化为日期类型的字符串!");
 }
}
 var d = this.date.getTime() - dat.getTime();
var d = this.date.getTime() - dat.getTime();
 return d>0?1:(d==0?0:-1);
return d>0?1:(d==0?0:-1);
 }
}
 }
}


 var d= new PowerDate(" 98-5/1 ");//实例化一个PowerDate对象
var d= new PowerDate(" 98-5/1 ");//实例化一个PowerDate对象
 d.setIsFmtZero(true);//设置为用0补位输出
d.setIsFmtZero(true);//设置为用0补位输出
 alert(d.getString("yy-mm-dd hh:mi:ss.ms"));//输出日期字符串
alert(d.getString("yy-mm-dd hh:mi:ss.ms"));//输出日期字符串

 //-->
//-->
 </script>
</script>


 新加了记算日期的方法,请大家帮测一下
新加了记算日期的方法,请大家帮测一下


 /**//*功能:返回两日期之差
/**//*功能:返回两日期之差
 *参数:pd   PowerDate对象
 *参数:pd   PowerDate对象
 *    type: 返回类别标识.yy:年,mm:月,dd:日,hh:小时,mi:分,ss:秒,ms:毫秒
 *    type: 返回类别标识.yy:年,mm:月,dd:日,hh:小时,mi:分,ss:秒,ms:毫秒
 *    intOrFloat :返回整型还是浮点型值 0:整型,1:浮点型
 *    intOrFloat :返回整型还是浮点型值 0:整型,1:浮点型
 */
 */

 this.calDateDistance = function (pd,type,intOrFloat)
this.calDateDistance = function (pd,type,intOrFloat) {
{
 var miSecMain = this.date.valueOf();
var miSecMain = this.date.valueOf();
 var miSecSub  = pd.getDate().valueOf();
var miSecSub  = pd.getDate().valueOf();
 var num=0;
var num=0;

 switch(type)
switch(type) {
{
 case "yy": num = this.getFullYear() - pd.getFullYear();
case "yy": num = this.getFullYear() - pd.getFullYear();
 break;
break;
 case "mm": num = (this.getFullYear() - pd.getFullYear())*12+this.getMonth()-pd.getMonth();
case "mm": num = (this.getFullYear() - pd.getFullYear())*12+this.getMonth()-pd.getMonth();
 break;
break;
 case "dd": num = this.fmtRtnVal((miSecMain-miSecSub)/86400000,intOrFloat);
case "dd": num = this.fmtRtnVal((miSecMain-miSecSub)/86400000,intOrFloat);
 break;
break;
 case "hh": num = this.fmtRtnVal((miSecMain-miSecSub)/3600000,intOrFloat);
case "hh": num = this.fmtRtnVal((miSecMain-miSecSub)/3600000,intOrFloat);
 break;
break;
 case "mi": num = this.fmtRtnVal((miSecMain-miSecSub)/60000,intOrFloat);
case "mi": num = this.fmtRtnVal((miSecMain-miSecSub)/60000,intOrFloat);
 break;
break;
 case "ss": num = this.fmtRtnVal((miSecMain-miSecSub)/1000,intOrFloat);
case "ss": num = this.fmtRtnVal((miSecMain-miSecSub)/1000,intOrFloat);
 break;
break;
 case "ms": num = (miSecMain-miSecSub);
case "ms": num = (miSecMain-miSecSub);
 break;
break;
 default:
default:
 throw new Error(-1,"没有您要求返回的类型,请检查输入参数!");
throw new Error(-1,"没有您要求返回的类型,请检查输入参数!");
 break;
break;
 }
}
 return num;
return num;
 };
};

 this.fmtRtnVal = function (val,intOrFloat)
this.fmtRtnVal = function (val,intOrFloat) {
{
 //alert(val);
//alert(val);
 return (intOrFloat == 0 ? Math.floor(val) : parseInt(val*100)/100);
return (intOrFloat == 0 ? Math.floor(val) : parseInt(val*100)/100);
 };
};



 测试语句:
测试语句:

 var d= new PowerDate(new Date());//实例化一个PowerDate对象
var d= new PowerDate(new Date());//实例化一个PowerDate对象
 alert(d.calDateDistance(new  PowerDate("2005/5/31"),"hh",1));//输出日期字符串
alert(d.calDateDistance(new  PowerDate("2005/5/31"),"hh",1));//输出日期字符串



