try {console.write ("Please enter your birthday in the form of a year-month-day:"); String stra = Console.ReadLine (); DateTime bir = convert.todatetime (stra); DateTime tod = Datetime.today; Stra = Bir. ToString ("Mm-dd");//Converts the input birthday to the month-day format string StrB = Tod. ToString ("Mm-dd");//Today month day Bir = DateTime.Parse (stra);//convert birthday string to date tod = DateTime.Parse (str B); TimeSpan ti = bir-tod;//time interval int j = ti. Days,k; if (J >= 0) {if (j = = 0) Console.WriteLine ("Your birthday today, Happy Birthday!"); else Console.WriteLine ("Your birthday is still there" +j+ "Day");//How long is the birthday} Els e {DateTime tod2 = tod. AddYears (1); TimeSpan t2 = Tod2-tod; k = T2. Days; Bir = Bir. AddYears (1); Timespan t3 = Tod2-bir; k = T2. Days-t3. days;//the second method of judging Console.WriteLine ("Your birthday is past, next year's birthday is also" + (K+J) + "Days");//Next birthday, how long } Console.WriteLine ("Your Birthday is in" + Bir. DayOfWeek + "," + "is the first birthday of the year" + Bir. DayOfYear + "Day"); } catch {Console.WriteLine ("You entered the wrong format!"); } console.readline ();
After-school homework--datetime application, judge how long after birthday and so on