文件名 year.jsp
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*" %>
<%@ page import="java.util.*,java.io.*,java.text.*"%>
<%
/** *//**
*原文:http://topic.csdn.net/t/20031201/19/2515519.html
* LK 整理 版
*/
//世纪万年历
//农历每月的天数
int everymonth[][]={
{8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1},
{0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2},
{0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3},
{5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4},
{0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5},
{0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6},
{4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7},
{0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8},
{0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9},
{2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10},
{0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11},
{6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12},
{0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1},
{0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2},
{5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3},
{0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4},
{0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5},
{2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6},
{0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7},
{7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8},
{0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9},
{0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10},
{5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11},
{0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12},
{0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1},
{4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2},
{0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3},
{0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4},
{2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5},
{0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6},
{6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7},
{0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8},
{0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9},
{5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10},
{0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11},
{0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12},
{3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1},
{0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2},
{7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3},
{0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4},
{0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5},
{6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6},
{0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7},
{0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8},
{4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9},
{0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10},
{0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11},
{2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12},
{0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1},
{7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2},
{0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3},
{0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4},
{5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5},
{0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6},
{0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7},
{3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8},
{0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9},
{8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10},
{0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11},
{0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12},
{6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1},
{0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2},
{0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3},
{4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4},
{0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5},
{0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6},
{3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7},
{0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8},
{7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9},
{0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10},
{0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11},
{5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12},
{0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1},
{0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2},
{4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3},
{0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4},
{8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5},
{0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6},
{0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7},
{6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8},
{0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9},
{0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10},
{4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11},
{0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12},
{10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1},
{0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2},
{0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3},
{6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4},
{0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5},
{0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6},
{5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7},
{0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8},
{0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9},
{3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10},
{0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11},
{8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12},
{0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1},
{0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2},
{5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3},
{0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4},
{0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5},
{4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6},
{0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7},
{0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8},
{2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9},
{0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10},
{7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11},
{0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12},
{0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1},
{5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2},
{0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3},
{0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4},
{4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5},
{0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6},
{9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7},
{0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8},
{0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9},
{6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10},
{0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11},
{0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12},
{4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1}
};
//农历天干
String[] mten={"null","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
//农历地支
String[] mtwelve={"null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)",
"巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)"};
//农历月份
String[] mmonth={"闰","正","二","三","四","五","六",
"七","八","九","十","十一","十二","月"};
//农历日
String[] mday={"null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
"廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
//赋给初值
//天干地支
int ten=0;
int twelve=0;
//星期
int week=5;
//农历日
int md=0;
//农历月
int mm=0;
//阳历总天数 至1900年12月21日
int total=11;
//阴历总天数
int mtotal=0;
//获得当日日期
//today=getdate();
GregorianCalendar today = new GregorianCalendar();
//如果没有输入,设为当日日期
String s_year=null,s_month=null;
s_year=request.getParameter("year");
s_month=request.getParameter("month");
int year,month;
if(s_year==null){
year = today.get(Calendar.YEAR);
month = today.get(Calendar.MONTH);
}else{
year=Integer.valueOf(s_year).intValue();
month=Integer.valueOf(s_month).intValue();
month=month-1;
}
//计算到所求日期阳历的总天数-自1900年12月21日始
//先算年的和
for(int y=1901;y<year;y++){
total+=365;
if(y%4==0)total ++;
}
//再加当年的几个月
switch(month){
case 11:
total+=30;
case 10:
total+=31;
case 9:
total+=30;
case 8:
total+=31;
case 7:
total+=31;
case 6:
total+=30;
case 5:
total+=31;
case 4:
total+=30;
case 3:
total+=31;
case 2:
total+=28;
case 1:
total+=31;
}
//如果当年是闰年还要加一天
if(year%4==0 && month>1){
total++;
}
//顺便算出当月1日星期几
today.set(year,month,1);
week=today.get(Calendar.DAY_OF_WEEK);
//用农历的天数累加来判断是否超过阳历的天数
int flag1=0;//判断跳出循环的条件
int j=0,i=1;
while(j<=120){
i=1;
while(i<=13){
mtotal+=everymonth[j][i];
if(mtotal>=total){
flag1=1;
break;
}
i++;
}
if(flag1==1)break;
j++;
}
//计算所求月份1号的农历日期
md=everymonth[j][i]-(mtotal-total);
//月头空开的天数
int k=week-1;
//是否跨越一年
int dd=0;
switch(month){
case 0:
case 2:
case 4:
case 6:
case 7:
case 9:
case 11:
dd=31;
break;
case 3:
case 5:
case 8:
case 10:
dd=30;
break;
case 1:
if(year%4==0){
dd=29;
}else{
dd=28;
}
break;
}
//是否跨越一年
int ty=0;
if(((everymonth[j][0]!=0 && i==13)||(everymonth[j][0]==0 && i==12))&&((mtotal-total)<dd))ty=1;
%>
<html>
<head>
<title>jsp万年历</title>
<style type="text/css">
<!--
input {font-size:9pt;}
A:link {text-decoration: underline;font-size:9pt;color:000059}
A:visited {text-decoration: underline;font-size:9pt;color:000059}
A:active {text-decoration: none;font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
</head>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgcolor="#F0F6E2">
<table width=640 bgcolor="#F0F6E2"><tr><td >
<%
//打印年月抬头
out.println("<div align=\"center\"><b><font size=\"2\">"+year+"年"+(month+1)+"月</font></b> ");
if(ty==0){
out.println(" <b><font size=\"2\">"+mten[everymonth[j][14]]+mtwelve[everymonth[j][15]]+"年</font></b> ");
}else{
out.println(" <b><font size=\"2\">"+mten[everymonth[j][14]]+mtwelve[everymonth[j][15]]+"/"+mten[everymonth[j+1][14]]+mtwelve[everymonth[j+1][15]]+"年</font></b></div>");
}
out.println("<form method=\"POST\" action=\"year.jsp\">");
//打印上一月,下一月
int ly,ny;
ly=year;
ny=year;
int last=month;
if(last==0){
last=12;
ly--;
}
int next=month+1;
if(next==12){
next=0;
ny++;
}
if(ly>1900)
out.println(" <div align='center'> <a href=\"year.jsp?year="+ly+"&month="+last+"\"><<上一个月</a> ");
if(ny<=2020)
out.println("<a href=\"year.jsp?year="+ny+"&month="+(next+1)+"\">下一个月>></a> ");
%>
<font color="#000000">年份:
<select name="year" onChange="">
<%
int ii;
for(ii=2020;ii>=1901;ii--){
%>
<option value="<%=ii%>" <%if(ii==year)out.println("selected");%>>
<%out.println(ii);%>
</option>
<%
}
%>
</select>
</font><font color="#000000">年</font><font color="#000000">
月份:
<select name="month" onChange="">
<%
for(ii=1;ii<=12;ii++){
%>
<option value="<%=ii%>" <%if(ii==month+1)out.println("selected");%>><%out.println(ii);%></option>
<%
}
%>
</select>
月 </font>
<input type="submit" value="查询" name="B1">
</p>
</form>
</td></td></table>
<div align="left">
<left>
<table border="0" width="640">
<tr>
<td align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期日</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期一</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期二</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期三</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期四</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期五</b></font></td>
<td width="14%" align="center" bgcolor="#004F8F"><font color="#ffffff"><b>星期六</b></font></td>
</tr>
<%
int day=1;
int line=0;
int s;
String color="#000000";
//while(day<=dd){
while(today.get(Calendar.MONTH)==month){
out.println("<tr>");
//for(int jii=Calendar.SUNDAY;jii < week;jii++)
// out.println("<td width=\"14%\" align=\"center\" bgcolor=\"#EEEDDB\"> </td>");
for(s=1;s<=7;s++){
if(k!=0||day>dd){
out.println("<td width=\"14%\" align=\"center\" bgcolor=\"#EEEDDB\"> </td>");
k--;
}else{
//设置字符颜色
switch(s){
case 6:
case 2:
case 3:
case 4:
case 5:
color="#000000";
break;
case 1:
color="#FF0000";
break;
case 7:
color="#008000";
break;
}
//生成中文农历
String chi;
if(md==1){//1日打印月份
if(everymonth[j][0]!=0 && everymonth[j][0]<i)
mm=i-1;
else
mm=i;
if(i==everymonth[j][0]+1 && everymonth[j][0]!=0)
chi=mmonth[0]+mmonth[mm];//闰月
else
chi=mmonth[mm]+mmonth[13];
}else{
chi=mday[md];
}
out.println("<td width=\"14%\" align=\"center\" bgcolor=\"#EEEDDB\" ><a href=\"rcb_body.jsp?year="+year+"&month="+(month+1)+"&day="+day+"\" target=main><font color=\""+color+"\"><b>"+day+" </b> <b><font size=\"2\">"+chi+"</font></b></font></a></td>");
day++;
today.add(Calendar.DAY_OF_MONTH,1);
//day=today.get(Calendar.DAY_OF_MONTH);
md++;
if(md>everymonth[j][i]){
md=1;
i++;
}
if((i>12 && everymonth[j][0]==0)||(i>13 && everymonth[j][0]!=0)){
i=1;
j++;
}
}
}
out.println("</tr>");
line++;
}
%>
</table>
</left>
</div>
<table width=640><tr><td height="20">
<%
//补足空行
for(int l=1;l<=(6-line);l++){
out.println("<table border=\"0\" width=\"100%\">");
out.println("<tr>");
out.println("<td width=\"100%\"><font color=\"#CCFFFF\"></font></td>");
out.println("</tr>");
out.println("</table>");
}
%>
</td></tr>
</table>
</body>
</html>
posted on 2008-02-19 14:28
lk 阅读(647)
评论(0) 编辑 收藏 所属分类:
j2ee