码迷,mamicode.com
首页 > 其他好文 > 详细

判断生日

时间:2015-08-08 09:03:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

          try
            {
                Console.Write("请输入您的生日");
                DateTime a = DateTime.Parse(Console.ReadLine());//闰年限定
                DateTime b = DateTime.Today;

                int ayear = a.Year;
                int amonth = a.Month;
                int aday = a.Day;
                int byear = b.Year;

                TimeSpan c = a - b;

                Console.WriteLine(c.TotalDays);

                int d = (int)c.TotalDays;
                int e = d % 365;
                Console.WriteLine(e);
                
                    Console.WriteLine("您的生日是今年的第" + a.DayOfYear + "");
                    if (byear % 4 != 0 && byear % 400!=0)
              {
                    if (c.TotalDays < 0 && e!=0)
                    {
                        Console.WriteLine("今年您的生日已经过了" + "距离您下个生日还有" + (e + 365) + "");
                    }
                    if (c.TotalDays > 0)
                    {
                        Console.WriteLine("距离您今年过生日还有" + c.TotalDays + "");
                    }
                    if (e == 0)//不执行
                    {
                        Console.WriteLine("祝您生日快乐");
                    }
          }
                else
                    Console.WriteLine("今年没有您的生日哦,请期待下一个闰年吧");
            }
            catch
            { Console.WriteLine("抱歉,您输入错误"); }

            Console.ReadLine();

 

判断生日

标签:

原文地址:http://www.cnblogs.com/nwj-0613/p/4712487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!