前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
| 1987/7/1 |
| static string WTBL= "日月火水木金土"; |
| static char[] WTBL= { '日','月','火','水','木','金','土' }; |
| static int[] MTBL= { 0,31,59,90,120,151,181,212,243,273,304,334 }; |
| static int yy, mm, dd; |
1999/1/1 金 3086 1945/1/10 水 22800 1991/1/15 火 5994 |
![]()
| 1987/7/1 |
string str;
string[] ymd;
Console.WriteLine("年月日= YYYY/MM/DD");
str = Console.ReadLine();
ymd= str.Split(new char[] {'/'});
yy= int.Parse(ymd[0]);
mm= int.Parse(ymd[1]);
dd= int.Parse(ymd[2]);
|
w= (yy-1)*365; //年*365
w+= (yy/4 - yy/100 + yy/400 + MTBL[mm-1] + dd);
if (mm<3 && uruu(yy)) w--;
return(w);
|
| 日付 | 経過日数 | 曜日 | 説明 |
|---|---|---|---|
| 1/1/1 | 738202 | 月 | 西暦元年元旦 |
| 1995/1/17 | 9893 | 火 | 阪神淡路大震災 |
| 1997/8/31 | 8936 | 日 | ダイアナ妃交通事故死 |
| 2001/9/11 | 7464 | 火 | アメリカ航空機テロ |
| 2011/3/11 | 3996 | 金 | 東日本大震災 |
| 1945/1/10 | 水 | ||
| 1951/9/11 | 火 | ||
| 1983/2/27 | 日 | ||
| 1989/1/15 | 日 |
![]()
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
/*★ 西暦1年1月1日からの通算日数を計算 前田 稔 ★*/
using System;
class Text
{
static int[] MTBL= { 0,31,59,90,120,151,181,212,243,273,304,334 };
static string[] WTBL= { "日","月","火","水","木","金","土" };
static int yy,mm,dd;
//★ Main()
public static void Main()
{ int today,count,week;
//西暦1年1月1日から今日までの日数を調べる
yy= DateTime.Today.Year;
mm= DateTime.Today.Month;
dd= DateTime.Today.Day;
today= days();
GetDate();
count= days();
week= count%7;
count= today-count+1;
Console.WriteLine("{0}年 {1}月 {2}日 ({3}曜日) 通算日数={4}",
yy, mm, dd, WTBL[week], count);
Console.ReadLine();
}
//★ 生年月日を入力して yy,mm,dd に設定
static void GetDate()
{
string str;
string[] ymd;
Console.WriteLine("生年月日= YYYY/MM/DD");
str = Console.ReadLine();
ymd= str.Split(new char[] {'/'});
yy= int.Parse(ymd[0]);
mm= int.Parse(ymd[1]);
dd= int.Parse(ymd[2]);
}
//★ 西暦1年1月1日からの通算日数を調べる関数
static 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);
}
//★ 閏年を調べる関数
static bool uruu(int year)
{ if (year%400L==0L) return(true);
if (year%100L==0L) return(false);
if (year%4L==0L) return(true);
return(false);
}
}
|