﻿var _DateTime={
CalendarData:[0x41A95,0xD4A,0xDA5,0x20B55,0x56A,0x7155B,0x25D,0x92D,0x5192B,0xA95,0xB4A,0x416AA,0xAD5,0x90AB5,0x4BA,0xA5B,0x60A57,0x52B,0xA93,0x40E95],
madd:[0,31,59,90,120,151,181,212,243,273,304,334],
tgString:"甲乙丙丁戊己庚辛壬癸",
dzString:"子丑寅卯辰巳午未申酉戌亥",
numString:"一二三四五六七八九十",
monString:"正二三四五六七八九十冬腊",
weekString:"日一二三四五六",
sx:"鼠牛虎兔龙蛇马羊猴鸡狗猪",
Browser:navigator.appName,
GetBit:function(m,n){return (m>>n)&1;},
e2c:function(TheDate){
var total,m,n,k;
var isEnd=false;
var cYear,cMonth,cDay,cHour;
var tmp=TheDate.getYear();
if(tmp<1900) tmp+=1900;
total=(tmp-2001)*365+Math.floor((tmp-2001)/4)+this.madd[TheDate.getMonth()]+TheDate.getDate()-23;
if(TheDate.getYear()%4==0&&TheDate.getMonth()>1) total++;
for(m=0;;m++){
k=(this.CalendarData[m]<0xfff)?11:12;
for(n=k;n>=0;n--){
if(total<=29+this.GetBit(this.CalendarData[m],n)){
isEnd=true;
break;
}
total=total-29-this.GetBit(this.CalendarData[m],n);
}
if(isEnd) break;
}
cYear=2001+m;
cMonth=k-n+1;
cDay=total;
if(k==12){
if(cMonth==Math.floor(this.CalendarData[m]/0x10000)+1) cMonth=1-cMonth;
if(cMonth>Math.floor(this.CalendarData[m]/0x10000)+1) cMonth--;
}
cHour=Math.floor((TheDate.getHours()+3)/2);
return new Array(cYear,cMonth,cDay,cHour);
},
GetCString:function(cA){
var tmp=this.tgString.charAt((cA[0]-4)%10)+this.dzString.charAt((cA[0]-4)%12)+"年("+this.sx.charAt((cA[0]-4)%12)+")";
if(cA[1]<1) tmp+="闰"+this.monString.charAt(-cA[1]-1);
else tmp+=this.monString.charAt(cA[1]-1);
tmp+="月";
tmp+=(cA[2]<11)?"初":((cA[2]<20)?"十":((cA[2]<30)?"廿":"卅"));
if(cA[2]%10!=0||cA[2]==10) tmp+=this.numString.charAt((cA[2]-1)%10);
if(cA[3]==13) tmp+="夜";
tmp+=this.dzString.charAt((cA[3]-1)%12)+"时";
return tmp;
},
GetString:function(TheDate){
var t1=TheDate.getYear();
if(t1<1900)t1+=1900;
var tmp=t1+"-"+(TheDate.getMonth()+1)+"-"+TheDate.getDate()+" "+TheDate.getHours()+":"
+((TheDate.getMinutes()<10)?"0":"")+TheDate.getMinutes()+" 星期"+this.weekString.charAt(TheDate.getDay());
return tmp;
}
}
function DT(){
switch(arguments.length){
case 0 : this.NowDate=new Date(); break;
case 1 : this.NowDate=new Date(arguments[0]); break;
case 3 : this.NowDate=new Date(arguments[0],arguments[1],arguments[2]); break;
case 4 : this.NowDate=new Date(arguments[0],arguments[1],arguments[2],arguments[3]); break;
case 5 : this.NowDate=new Date(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]); break;
case 6 : this.NowDate=new Date(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);
}
if(!this.NowDate) this.NowDate=new Date();
}
DT.prototype.getCDT=function(){return _DateTime.GetCString(_DateTime.e2c(this.NowDate));}
DT.prototype.getDT=function(){return _DateTime.GetString(this.NowDate);}
//使用示例:
//var dt=new DT();
//document.write(dt.getDT() + " " + dt.getCDT());
//节气
//<script type=text/javascript>
//var jq=new Array('0105小寒','0120大寒','0203立春','0218雨水','0305惊蜇','0320春分','0404清明','0419谷雨','0505立夏','0520小满','0605芒种','0621夏至','0706小暑','0722大暑','0807立秋','0822处暑','0907白露','0922秋分','1008寒露','1023霜降','1107立冬','1122小雪','1206大雪','1221冬至');
//var d=new Date();
//var s='';
//if (d.getMonth()<9) s+='0';
//s+=''+(d.getMonth()+1);
//if (d.getDate()<10) s+='0';
//s+=''+(d.getDate());
//var i=0;
//while(i<jq.length && s>=jq[i]) i++;i--;
//document.write('今天是',d.getYear(),'年',d.getMonth()+1,'月',d.getDate(),'日 正处于',jq[i].substr(4));
//</script> 
