Search

An introduction to coding and programming - Displaying the time

//#######                                        #####                              
//#       #    # #####  #      #  ####  # ##### #     #  ####  #####  ###### #####  
//#        #  #  #    # #      # #    # #   #   #       #    # #    # #      #    # 
//#####     ##   #    # #      # #      #   #   #       #    # #    # #####  #    # 
//#         ##   #####  #      # #      #   #   #       #    # #    # #      #####  
//#        #  #  #      #      # #    # #   #   #     # #    # #    # #      #   #  
//####### #    # #      ###### #  ####  #   #    #####   ####  #####  ###### #    # 

//***********************************************************************************************************************************
// Project      : Displaying the time
// Solution     : Entry level coding
// Project type : Console application
// Platform     : Microsoft.NET 6.00
// Created with : Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.6
// Created      : 03/10/2022
// Created By   : https://explicitcoder.com
//***********************************************************************************************************************************
// Instructions
// Select this project (Displaying the time) from the dropdown box next to the green arrow
// at the top of Visual studio and then click the green play button to start it.
// To stop the program you can either click the close button on the console window or click the red stop button.
//***********************************************************************************************************************************
// Description
// C# has built in date and time functions.
// To display the date and time we can call the built in functions and display it in the console window.
//***********************************************************************************************************************************

//***********************************************************************************************************************************
// SEE THE WEBSITE FOR MORE INFORMATION    https://explicitcoder.com/getting-started
//***********************************************************************************************************************************

namespace Displaying_the_time
{
    class Program
    {
        static void Main() // The program starts here. Main is the first method called when you run the program.
        {
            // Display the date and time in the default format.
            Console.WriteLine(DateTime.Now);

            // Display the date in the long format.
            Console.WriteLine(DateTime.Now.ToLongDateString());

            // Display the time in the long format.
            Console.WriteLine(DateTime.Now.ToLongTimeString());

            // Display the current year.
            Console.WriteLine(DateTime.Now.Year);

            // Display the current month.
            Console.WriteLine(DateTime.Now.Month);

            // Display the current day.
            Console.WriteLine(DateTime.Now.Day);

            // Without this line the program will end before you have time to see it.
            Console.ReadLine();
        }
    }
}