CSharp - Write program to Working with Date Components

Requirements

Learn about the various components of the DateTime object.

Demo

using System;
class Program{// ww  w.  j  av  a2  s. c  o  m
    static void Main(string[] args)
    {
        // Current date and time (using single statement) 
        DateTime now = DateTime.Now;

        // Picking up individual components 
        int day = now.Day;
        int month = now.Month;
        int year = now.Year;
        int hours = now.Hour;
        int minutes = now.Minute;
        int seconds = now.Second;
        DateTime justDateWithoutTime = now.Date;

        // Output 
        Console.WriteLine("Day: " + day);
        Console.WriteLine("Month: " + month);
        Console.WriteLine("Year: " + year);
        Console.WriteLine("Hours: " + hours);
        Console.WriteLine("Minutes: " + minutes);
        Console.WriteLine("Seconds: " + seconds);
        Console.WriteLine("Date component: " + justDateWithoutTime);

        // Formatting output our way 
        Console.WriteLine("Our output: " +
            year + ", " + month + "/" + day +
            " " +
            hours + " hours " + minutes + " minutes");
    }
}

Result