比原来多了“生肖”效果不错
效果:
2007年4月10日 星期二
丁亥年(猪)二月廿三
将以下代码另存为date.js,
function nl(){
//获取当前系统时间
curTime = new Date();
//星期名
var weekName= "星期日,星期一,星期二,星期三,星期四,星期五,星期六".split(/,/g);
//天干名称
var tianGang = "甲,乙,丙,丁,戊,己,庚,辛,壬,癸".split(/,/g);
//地支名称
var diZhi = "子,丑,寅,卯,辰,巳,午,未,申,酉,戌,亥".split(/,/g);
//属相名称
var shuXiang = "鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪".split(/,/g);
//农历日期名
var dayName = "*,初一,初二,初三,初四,初五,初六,初七,初八,初九,初十,十一,十二,十三,十四,十五,十六,十七,十八,十九,二十,廿一,廿二,廿三,廿四,廿五,廿六,廿七,廿八,廿九,三十".split(/,/g);
//农历月份名
var monName = "*,正,二,三,四,五,六,七,八,九,十,十一,腊".split(/,/g);
//公历每月前面的天数
var monthAdd = new Array(0, 31, 59, 90, 120, 151,181,212,243,273,304,334);
//农历数据
var nongliData = new Array(2635,333387,1701,1748,267701,694,2391,133423,1175,396438,3402,3749,331177,1453,694,201326,2350,465197,3221,3402,400202,2901,1386,267611,605,2349,137515,2709,464533,1738,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222,268949,3402,3493,133973,1386,464219,605,2349,334123,2709,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877);
//生成当前公历年、月、日 ==> GongliStr
var curYear = curTime.getFullYear();
var curMonth = curTime.getMonth()+1;
var curDay = curTime.getDate();
var gongliStr = curYear + "年";
if (curMonth < 10)
gongliStr = gongliStr + "0" + curMonth + "月";
else
gongliStr = gongliStr + curMonth + "月";
if (curDay < 10)
gongliStr = gongliStr + "0" + curDay + "日";
else
gongliStr = gongliStr + curDay + "日";
//生成当前公历星期 ==> WeekdayStr
var curWeekday = curTime.getDay();
var weekdayStr = weekName[curWeekday]
//计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
var theDate = (curYear - 1921) * 365 + Math.floor((curYear - 1921.0) / 4) + curDay + monthAdd[curMonth - 1] - 38
if ((curYear % 4) == 0 && curMonth > 2)
theDate ++;
//计算农历天干、地支、月、日
var isEnd = 0;
var m = 0,k,n;
while (1){
if (nongliData[m] < 4095)
k = 11
else
k = 12
n = k
while (1){
if (n < 0)
break;
//获取NongliData[m]的第n个二进制位的值
bit = nongliData[m]
for (var i=0;i< n;i++)
bit = Math.floor(bit / 2.0);
bit = bit % 2
if (theDate <= (29 + bit)){
isEnd = 1
break;
}
theDate -= 29 + bit;
n--;
}
if (isEnd == 1)
break;
m ++;
}
curYear = 1921 + m;
curMonth = k - n + 1;
curDay = theDate;
if (k == 12){
if (curMonth == (Math.floor(nongliData[m] / 65536.0) + 1))
curMonth = 1 - curMonth;
else If (curMonth > (Math.floor(NongliData(m) / 65536.0) + 1))
curMonth = curMonth - 1
}
var o=new Object();
o.year=new Date().getFullYear();
o.month=new Date().getMonth()+1;
o.date=new Date().getDate();
o.day=new Date().getDay();
o.dayName=weekName[o.day];
o.nYear=tianGang[((curYear - 4) % 60) % 10] + diZhi[((curYear - 4) % 60) % 12] + "年"
if (curMonth < 1)
o.nMonth = "闰" + monName[-1 * curMonth];
else
o.nMonth = monName[curMonth];
o.nMonth+="月";
o.nDate=dayName[curDay];
o.nZodiac=shuXiang[((curYear - 4) % 60) % 12];
return o
}
var ny=nl();
var s="<style>#sheneyan_calc{width:120px;}#sheneyan_calc li{color:#FF0000;font:14px;LINE-HEIGHT:26px;list-style:none}</style>"+(ny.year)+"年"+(ny.month)+"月"+(ny.date)+"日 "+ny.dayName+"<br>"+ny.nYear+"("+ny.nZodiac+")"+ny.nMonth+ny.nDate+""
document.write(s)