MyMath

<pre name="code" class="csharp">{
    class Program
    {
        static void Main(string[] args)
        {
            Time t = new Time();
   
            try
            {
                Console.WriteLine("请输入小时");
                t.Hour = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入分钟");
                t.Minute = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入秒");
                t.Second = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
                return;
            }

            Time T = new Time();

            T.hour = DateTime.Now.Hour;
            T.minute = DateTime.Now.Minute;
            T.second = DateTime.Now.Second;



            Console.WriteLine("输入的时间为{0:00}:{1:00}:{2:00}", t.hour, t.minute, t.second);
            Console.WriteLine("当前的时间为{0:00}:{1:00}:{2:00}", T.hour, T.minute, T.second);
            t.DisPaly();
            T.DisPaly();




            Console.ReadKey();
        }
    }
    class Time
    {

        public int hour;
        public int minute;
        public int second;
        public int Hour
        {
            get
            {
                return Hour;
            }
            set
            {
                if (value > 0 && value < 24)

                    hour = value;


                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");

                }
            }
        }

        public int Minute
        {
            get
            {
                return Minute;
            }
            set
            {
                if (value > 0 && value < 60)
                    minute = value;
                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");
                }
            }
        }
        public int Second
        {
            get
            {
                return Second;
            }
            set
            {
                if (value > 0 && value < 60)
                    second = value;
                else
                {
                    Console.Clear();
                    throw new Exception("输入的时间不正确");
                }
            }
        }
        public int TimePeriod()
        {
            int a;
            a = hour * 3600 + minute * 60 + second;
            return a;
        }

        public void DisPaly()
        {
            Console.WriteLine("与零时刻的时间间隔:{0}",TimePeriod());

        }
    }
}  






                                    
发布了13 篇原创文章 · 获赞 0 · 访问量 2944
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览