string s = "11:25:00"; //闹钟的时间 DateTime dd = DateTime.Now; string dt = dd.ToString("yyyy-MM-dd");//设定每天到这个时间就自动响铃 string time = dt + " " + s; DateTime nd = Convert.ToDateTime(time); while (true) { Console.Clear(); Console.WriteLine(DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss")); if (nd.ToString("yyyyMMddhhmmss").Equals(DateTime.Now.ToString("yyyyMMddhhmmss"))) //.Equals是等号的意思,也可用=号 { Console.WriteLine("时间到了 aaaaaaaaaaa..."); Console.WriteLine("是否要关闭闹钟,关闭请输入Y,否则请输入N"); string s1 = Console.ReadLine(); if (s1.ToUpper() == "Y") { break; } else if (s1.ToUpper() == "N") { nd = nd.AddSeconds(59); } else { Console.WriteLine("输入错误!"); break; } } Thread.Sleep(1000);//限制While循环速度, }