Mega Code Archive

 
Categories / C# / Date Time
 

A simple clock

/* C#: The Complete Reference  by Herbert Schildt  Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // A simple clock.     using System;      public class SimpleClock {     public static void Main() {       string t;      int seconds;        DateTime dt = DateTime.Now;      seconds = dt.Second;        for(;;) {        dt = DateTime.Now;          // update time if seconds change        if(seconds != dt.Second) {          seconds = dt.Second;            t = dt.ToString("T");            if(dt.Minute==0 && dt.Second==0)             t = t + "\a"; // ring bell at top of hour            Console.WriteLine(t);        }      }    }  }