c#控制台程式-“輸入指定年月日查詢出星期幾”

來源:互聯網
上載者:User

標籤:控制台

其中涉及一個演算法:

基姆拉爾森計算公式W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1) mod 7在公式中d表示日期中的日數,m表示月份數,y表示年數。注意:在公式中有個與其他公式不同的地方:把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10則換算成:2003-13-10來代入公式計算。代碼如下:

            Console.WriteLine("**************************");            Console.WriteLine("輸入指定年月日查詢出星期幾");            Console.WriteLine("By:YYS");            Console.WriteLine("今天是{0}年{1}月{2}日 星期{3}", DateTime.Now.Year,DateTime.Now.Month, DateTime.Now.Day, (int)DateTime.Now.DayOfWeek);            Console.WriteLine("**************************");            Console.ForegroundColor = ConsoleColor.Red;            Console.WriteLine("請輸入年:");            int y = System.Int32.Parse(Console.ReadLine());            Console.WriteLine("請輸入月");            int m = System.Int32.Parse(Console.ReadLine());            Console.WriteLine("請輸入日");            int d = System.Int32.Parse(Console.ReadLine());            int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7;            Console.WriteLine("{0}年{1}月{2}日是星期{3}",y,m,d,week);            Console.ReadKey(); 


c#控制台程式-“輸入指定年月日查詢出星期幾”

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.