Enter a person's birthdate (1) to calculate the person's age; (2) to calculate from now till 60 years old

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.