/*★ 西暦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);
}
}
|