Mega Code Archive

 
Categories / C# Tutorial / Date Time
 

Get current time

using System;      class MainClass {     public static void Main() {       string t;      int seconds;        DateTime dt = DateTime.Now;      seconds = dt.Second;        // update time if seconds change      if(seconds != dt.Second) {        seconds = dt.Second;          t = dt.ToString("T");        Console.WriteLine(t);      }    }  }