日历
1.判断闰年
成都创新互联公司自2013年起,先为临沂等服务建站,临沂等地企业,进行企业商务咨询服务。为临沂企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
2.通过年和月的确定 判断月有几天
3.通过年 月 日 来判断星期几 基姆拉尔森计算公式
- using System;
- using System.Text;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Collections;
- namespace 日历
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack) //该值指示该页是否正为响应客户端回发而加载,或者它是否正被首次加载和访问,如果是为响应客户端回发而加载该页,则为true;否则为 false。
- {
- ArrayList arrList1 = new ArrayList();
- for (int i = 2000; i <= 2012; i++)
- {
- arrList1.Add(i);
- }
- year.DataSource = arrList1;
- year.DataBind();
- ArrayList arrList2 = new ArrayList();
- for (int i = 1; i <= 12; i++)
- {
- arrList2.Add(i);
- }
- month.DataSource = arrList2;
- month.DataBind();
- ArrayList arrList3 = new ArrayList();
- for (int i = 1; i <= 31; i++)
- {
- arrList3.Add(i);
- }
- day.DataSource = arrList3;
- day.DataBind();
- }
- }
- protected void day_SelectedIndexChanged(object sender, EventArgs e)
- {
- int[] a = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //将数组作为控件数据源
- int[] b = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- int s1 = Int32.Parse(year.Text);
- int s2 = Int32.Parse(month.Text);
- int s3 = Int32.Parse(day.Text);
- if ((s1%4 == 0 && s1%100 != 0) || (s1%400 == 0)) //判断闰年
- {
- ArrayList arrList3 = new ArrayList();
- for (int i = 1; i <= b[s2-1]; i++) //是闰年 则用b数组中的天数
- {
- arrList3.Add(i);
- }
- day.DataSource = arrList3;
- day.DataBind();
- }
- else
- {
- ArrayList arrList3 = new ArrayList();
- for (int i = 1; i <= a[s2 - 1]; i++) //不是闰年 则用a数组中的天数
- {
- arrList3.Add(i);
- }
- day.DataSource = arrList3;
- day.DataBind();
- }
- xinqi.Text = caculateweekday(s1, s2, s3);
- }
- String caculateweekday(int y, int m, int d) //计算星期几
- {
- if (m == 1) { m = 13; y--; }
- if (m == 2) { m = 14; y--; }
- int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7 + 1;//基姆拉尔森计算公式
- string weekstr = "";
- switch (week)
- {
- case 1: weekstr = "星期一"; break;
- case 2: weekstr = "星期二"; break;
- case 3: weekstr = "星期三"; break;
- case 4: weekstr = "星期四"; break;
- case 5: weekstr = "星期五"; break;
- case 6: weekstr = "星期六"; break;
- case 7: weekstr = "星期日"; break;
- }
- return weekstr;
- }
- protected void zz(object sender, EventArgs e) //改变天数时 改变星期数 我觉得这里可以优化
- {
- int s1 = Int32.Parse(year.Text);
- int s2 = Int32.Parse(month.Text);
- int s3 = Int32.Parse(day.Text);
- xinqi.Text = caculateweekday(s1, s2, s3);
- }
- }
- }
当前名称:日历
标题链接:http://cdiso.cn/article/gcedoi.html