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

    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 ());
            }
        }
    }

  • 相关阅读:
    辅助构造器
    pycharm、webstorm和idea激活码
    Executor
    生产者和消费者模型
    Master和worker模式
    Future模式
    记事本中快速查看数字对应的ASCII
    C#中时间戳和日期相互转换
    Dos命令调用FlashFXP上传文件
    curl 上传文件
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3002633.html
Copyright © 2011-2022 走看看