C# Getting Current Time

In C# the DateTime.Now property is used to get the current time. We can display time in various formats.

Let's examine the examples below...

namespace ConsoleApplicationTest
{
    class Program {

        static void Main(string[] args) {

            DateTime dNow  = DateTime.Now;
            string   dNow2 = DateTime.Now.ToString("h:mm:ss");            
            
            Console.WriteLine(dNow);
            Console.WriteLine(dNow2);
            
            Console.ReadLine();
        }
    }
}       


C#

You May Interest

C# Finding the Path to the Windows AppData Folder

C# Finding the Desktop Path

C# Finding the Path to the Windows System32 Folder

C# Finding the Path to My Documents Folder

C# Non-Restart Check If Application is Open