CSharp - Write program to Get current Date and Time


You will write a program that displays the current date and time.


DateTime type contains various components of a single instance of time, such as day, month, year, hour, minute, second, and so on.


using System;

class Program/*from ww w. ja  v a2 s .  com*/
    static void Main(string[] args)
        // Variable of DateTime type, at first empty 
        DateTime now;

        // Storing of current date and time into our variable 
        now = DateTime.Now;

        // Output 
        Console.WriteLine("Now is " + now);