以下的代码是可以自己测试!如果大家有兴趣可以直接去看看
<% @ Import Namespace="System" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<% @ Import Namespace="System.Text" %>
<% @ Import Namespace="System.IO" %>
<script language="C#" runat=server>
public class Control_year
{
public Control_year()
{
}
public int judge_if_year = 0;
public int www;
public string[,] org_data(string Thisyears, string Thismonths)
{
int i =1;
int j =0;
int k =0;
int num_day = 0;
int mydata =1;
string[] num_dig = new string[2];
//num_dig = change_type(Thisyears,Thismonths);
//转换成数字型
int Thisyear =Convert.ToInt32(Thisyears);
int Thismonth = Convert.ToInt32(Thismonths);
int [,] return_data = new int[6,7]; //返回的是个六行七列的二维数组
int [] return_month_day = new int[13];
string [,] return_string =new string[6,7];
if ((Thisyear%4 == 0 && Thisyear%100 != 0) || Thisyear%400 == 0)
{
judge_if_year = 1;
}
else
{
judge_if_year = 0;
}
//一年有12个月
return_month_day[0] = 0;
return_month_day[1] = 0;
if (judge_if_year == 0)
{
return_month_day[2] =2;
}
else
{
return_month_day[2] =3;
}
return_month_day[3] = 0;
return_month_day[4] = 1;
return_month_day[5] = 0;
return_month_day[6] = 1;
return_month_day[7] = 0;
return_month_day[8] = 0;
return_month_day[9] = 1;
return_month_day[10]= 0;
return_month_day[11]= 1;
return_month_day[12]= 0;
num_day = count_day_index(Thisyear,Thismonth,1,judge_if_year);
for(j=num_day;j<7;j++)
{
return_data[0,j] = mydata++;
// mydata ++;
}
//以上这个循环是对1号到7号之间进行判断
while (mydata <32 - return_month_day[Thismonth])
{
return_data[i,k] = mydata++;
//mydata ++;
k++;
k = k%7;
if (k == 0)
{
i++;
}
}
for(i=0;i<6;i++)
{
for(j=0;j<7;j++)
{
if (return_data[i,j] !=0)
{
return_string[i,j] = Convert.ToString(return_data[i,j]);
}
else
{
return_string[i,j] = "";
}
}
}
return return_string;
//计算某天是星期几
}
//计算某天是星期几的函数
public int count_day_index(int strYear,int strMonth,int strDate,int judge_if_year)
{
int this_year = strYear ;
int this_month = strMonth;
int this_date = strDate;
int[] diff_month_day = new int[13];
diff_month_day[0] = 0;
diff_month_day[1] = 0;
if (judge_if_year == 1)
{
diff_month_day[2] =-2;
}
else
{
diff_month_day[2] =-3;
}
diff_month_day[3] = 0;
diff_month_day[4] = -1;
diff_month_day[5] = 0;
diff_month_day[6] = -1;
diff_month_day[7] = 0;
diff_month_day[8] = 0;
diff_month_day[9] = -1;
diff_month_day[10]= 0;
diff_month_day[11]= -1;
diff_month_day[12]= 0;
//现在我们从1990 年开始计算
int Total_year = 0;
int[] flag = new int[100];
int i = 0;
int j = 0;
int num =0;
int Total_month =0;
int Total_day = 0;
for (i=1990; i <this_year; i++)
{
if ((i%4 == 0 && i%100 != 0) || i%400 == 0)
{
//flag[num] = i;
num = num +1;
}
}
Total_year = (this_year - 1990)*365 + num ; //计算计算前面几年的总天数
Total_month = (this_month-1)*31; //计算本年的该月之前的的总天数
for(j=0; j<this_month ;j++)
{
Total_month = Total_month + diff_month_day[j];
}
Total_day = Total_year + Total_month + this_date;
//www = Total_day;
return Total_day%7 ;
}
public string[] change_type(string Thisyears, string Thismonths)
{
int this_years = 0;
int this_months = 0;
string [] dig_num = new string[2];
if (Thisyears !="" && Thismonths !="")
{
try
{
this_years = Convert.ToInt32(Thisyears);
this_months = Convert.ToInt32(Thismonths);
}
catch(Exception ee)
{
if (ee.ToString().Length !=0)
{
dig_num[0] = "输入的类型不正确,请重新输入";
dig_num[1] = "谢谢合作";
return dig_num;
}
}
if (this_years <1990&& this_months >12)
{
dig_num[0] = "请输入大于1990的年份";
dig_num[1] = "谢谢合作";
return dig_num;
}
else
{
dig_num[0] = Convert.ToString(this_years);
dig_num[1] = Convert.ToString(this_months);
}
}
return dig_num;
}
}
</script>
<% @ Page Language="C#" Debug="true" %>
<%
Control_year tester = new Control_year();
string year = "2002";
string month = "9";
string [,] endding = tester.org_data( year, month );
Response.Write("<table border = 1>");
for( int i = 0; i < endding.GetLength( 0 ); i ++ )
{
Response.Write("<tr>");
for( int j = 0; j < endding.GetLength( 1 ); j ++ )
{
Response.Write("<td>");
Response.Write(endding[i,j].ToString());
Response.Write("</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
%>