Enter a person's birthdate (input in string format, such as 1987-4-1) using the DateTime and TimeSpan classes, (1) Calculate the person's age; (2) Calculate from now until 60 years old
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication5
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("Enter the Year of birth ");
String n = Console. ReadLine ();
Int n1;
Int. TryParse (n, out n1 );
Console. WriteLine ("Enter the birthdate yue ");
String y = Console. ReadLine ();
Int y1;
Int. TryParse (y, out y1 );
Console. WriteLine ("Enter the Date of Birth ");
String r = Console. ReadLine ();
Int r1;
Int. TryParse (r, out r1 );
DateTime dt = new DateTime (n1, y1, r1 );
Console. WriteLine (dt. tow.datestring ());
Int nl = DateTime. Now. Year-n1;
Console. WriteLine ("his age is {0}", nl );
DateTime dt1 = new DateTime (n1 + 60, y1, r1 );
TimeSpan ts = dt1-DateTime. Now;
Console. WriteLine ("from now till the age of 60, total {0} Days", ts. Days. ToString ());
}
}
}
Share: