1 DateTime bdDT = new DateTime(); 2 DateTime timenow = DateTime.Now; 3 Console.WriteLine("请输入您的年龄"); 4 int age = int.Parse(Console.ReadLine()); 5 Console.WriteLine("请输入你今年的生日,如2015-10-5"); 6 string bdST = Console.ReadLine(); 7 bdDT = Convert.ToDateTime(bdST); 8 int intYearNow=bdDT .Year ; 9 int intYearNext=bdDT .Year +1; 10 int Days=0; 11 int intDay = bdDT.Day; 12 int intMonth = bdDT.Month; 13 int intDayNow = timenow.Day; 14 int intMonthNow = timenow.Month; 15 int DayNowNum=timenow .DayOfYear; 16 int DaybdNum=bdDT .DayOfYear; 17 int bdNextNum=0; 18 //判断今年是不是闰年 19 if (intYearNow%4==0&&intYearNow %100!=0) 20 { 21 Days =366; 22 if (intMonth >2) 23 bdNextNum =DayNowNum-1; //如果今年是闰年,那第二年肯定不是闰年 24 else 25 bdNextNum =DayNowNum; //小于2月则每一年的第几天生日不会改变 26 } 27 28 else 29 Days =365; 30 if (intDayNow - intDay >= 0) 31 { 32 if (intMonthNow - intMonth >= 0) 33 Console.WriteLine("您还有" + (intMonthNow - intMonth) + "个月零" + (intDayNow - intDay) + "天,总共" + (Days-DayNowNum + bdNextNum) + "天,就过生日啦"); 34 else 35 Console.WriteLine("您还差" + (intDayNow - intDay) + "天不到" + (intMonth - intMonthNow) + "个月总共" + (DaybdNum - DayNowNum) + "天,就过生日啦"); 36 } 37 else 38 { 39 if (intMonthNow - intMonth >= 0) 40 Console.WriteLine("您还差" + (intDay - intDayNow) + "天不到" + (12 - intMonthNow + intMonth) + "个月总共" + (Days - DayNowNum + bdNextNum) + "天就过生日了"); 41 else 42 Console.WriteLine("您还差" + (intDay - intDayNow) + "天不到" + (intMonth - intMonthNow) + "个月总共" + (DaybdNum - DayNowNum) + "天就过生日了"); 43 } 44 Console.WriteLine("您的出生日期为"+(bdDT .Year-age)+"年"+intMonth+"月"+intDay+"日"); 45 46 Console.ReadLine();
时间: 2024-12-10 08:43:12