zoukankan      html  css  js  c++  java
  • 输入某人出生日期(以字符串方式输入,如1987-4-1)使用DateTime和TimeSpan类,(1)计算其人的年龄;(2)计算从现在到其60周岁期间,总共多少天。

    http://blog.csdn.net/w92a01n19g/article/details/8764116

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication5
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入出生年份");
                string n = Console.ReadLine();
                int n1;
                int.TryParse(n, out n1);
                Console.WriteLine("请输入出生yue份");
                string y = Console.ReadLine();
                int y1;
                int.TryParse(y, out y1);
                Console.WriteLine("请输入出生日子");
                string r = Console.ReadLine();
                int r1;
                int.TryParse(r, out r1);
                DateTime dt = new DateTime(n1,y1,r1);
                Console.WriteLine(dt.ToShortDateString ());
                int nl = DateTime.Now.Year - n1;
                Console.WriteLine("他的年龄是{0}",nl);
                DateTime dt1 = new DateTime(n1+60, y1, r1);
                TimeSpan ts = dt1 - DateTime.Now;
                Console.WriteLine("从现在到其60周岁期间,总共{0}天",ts.Days.ToString ());
            }
        }
    }

  • 相关阅读:
    Python深浅拷贝&垃圾回收&with语句
    面向对象
    三器(装饰器,生成器,迭代器)
    Redis数据类型&优缺点&持久化方式
    localStroge和sessionStorge
    redis哨兵&codis
    Redis分布式锁
    技术点剖析
    【牛客网】牛客练习赛4 A Laptop【树状数组+离散化】
    组合数有关的公式及常用求和【数学--排列组合】
  • 原文地址:https://www.cnblogs.com/Echo529/p/6382340.html
Copyright © 2011-2022 走看看