关于闹钟的题

static void Main(string[] args)
        {
          
                DateTime dt = DateTime.Now;
                Console.WriteLine(dt);
                DateTime nz = Convert.ToDateTime("2015-4-2  17:00"); //将nz的时间转换为电脑能识别的时间
             
                for (int i = 1; i < 1000; i++)
                {
                   
                  dt = dt.AddMinutes(1); //系统时间加1分钟
                     Console.WriteLine(dt.ToShortTimeString());   //输出的时间为短的时间,就是只有时间,没有日期
                    
                    if(nz.ToShortTimeString().Equals(dt.ToShortTimeString()))  //两个时间相比的公式!!  这是相等的公式 Equals 相等的意思
                    {
                        Console.WriteLine("到点了");
                        Console.WriteLine("是否关闭闹钟(Y/N)");
                        string b = Console.ReadLine();
                        if (b.ToUpper()=="N")  //将字母转换为大写
                        {
                            nz = nz.AddMinutes(5); //闹钟的时间在原来的基础上加5分钟
                       
                        }
                        else
                        {
                            Console.WriteLine("闹钟已停");
                            break;
                        }
                    }

                }
            Console.ReadLine();
               
           
        }

posted @ 2015-04-02 19:25  XCml  阅读(127)  评论(0编辑  收藏  举报