OJ Problem 3447 C#解密出生日期

题目描述

使用C#编写一个静态方法。该方法能够根据出生日期,(1)计算此人的年龄;(2)计算从现在到其60周岁期间,总共多少天。

输入

一个人的出生日期;

输出

此人的年龄;此人从现在到其60周岁期间,总共多少天。

样例输入

2019-12-4

样例输出

0
21914
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Age(DateTime dt)
        {
            //DateTime Nowdt=DateTime.Now;该题nowtime要取2019.12.4
            DateTime Nowdt = new DateTime(2019, 12, 4);
            //1.计算此人年龄
            TimeSpan ts1 = Nowdt - dt;
            int age = ts1.Days / 365;
            //2.计算此人60周岁的日期
            dt=dt.AddYears(60);
            //3.求此人从现在到60周岁的时间间隔
            TimeSpan ts = dt - Nowdt;
            //4.输出,注意时间间隔转化为天数
            Console.WriteLine("{0}", age);
            Console.WriteLine("{0}", ts.Days-1);
        }
        static void Main(string[] args)
        {
            DateTime Dt = Convert.ToDateTime(Console.ReadLine());
            Age(Dt);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wangws_sb/article/details/104814559