前田稔(Maeda Minoru)の超初心者のプログラム入門
int[] MTBL= { 0,31,59,90,120,151,181,212,243,273,304,334 }; string[] WTBL= { "日","月","火","水","木","金","土" }; int yy,mm,dd; void Button1_Click(object sender, EventArgs e) { string[] ymd; string str; int today,count,week; //西暦1年1月1日から今日までの日数を調べる yy= DateTime.Today.Year; mm= DateTime.Today.Month; dd= DateTime.Today.Day; today= days(); //TextBox から入力された日付を取得 str= TextBox1.Text; ymd= str.Split(new char[] {'/'}); yy = Convert.ToInt32(ymd[0]); mm = Convert.ToInt32(ymd[1]); dd = Convert.ToInt32(ymd[2]); count= days(); week= count%7; count= today-count+1; Label1.Text = "生年月日=" + str + " 曜日=" + WTBL[week] + "曜日 通算日数=" + Convert.ToString(count); } //★ 西暦1年1月1日からの通算日数を調べる関数 int days() { int w; w= (yy-1)*365; //年*365 w+= (yy/4 - yy/100 + yy/400 + MTBL[mm-1] + dd); if (mm<3 && uruu(yy)) w--; return(w); } //★ 閏年を調べる関数 bool uruu(int year) { if (year%400==0) return(true); if (year%100==0) return(false); if (year%4==0) return(true); return(false); } |
youbi4.aspx のソースコード
ソースコードが表示されない場合は、ブラウザのメニューから「ソースの表示」を選択して下さい。