Get current time : DateTime Now « Date Time « C# / CSharp Tutorial





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); 
    } 
  } 
}










13.2.DateTime Now
13.2.1.Extracting the current date/time: Now and UtcNow
13.2.2.Get current time
13.2.3.Check the current second