CSharp examples for Language Basics:Date Time
Using a Timer with the DateTime
using System;// ww w . jav a2 s. c o m using System.Timers; class NetTimer { public static void Main() { Timer myTimer = new Timer(); myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent ); myTimer.Interval = 1000; myTimer.Start(); while ( Console.Read() != 'q' ) { ; // do nothing... } } public static void DisplayTimeEvent( object source, ElapsedEventArgs e ) { Console.Write("\r{0}", DateTime.Now); } }