C# Exercise: 215 Date and time

In this exercise, you need to create a program that displays the current date and time in the following format:

"Today is 6 of February of 2015. It´s 03:23:12".

To achieve this, you will use system functionalities to get the current date and time, and then format them according to the specified format.

This exercise will allow you to practice working with dates and times in C#, as well as displaying this information in a customized format in the console.

 Exercise

Date and time

 Objetive

Create a program to display the current date and time with the following format:

Today is 6 of February of 2015. It´s 03:23:12

 Example Code

// Import the System namespace which provides fundamental classes for date, time, and console operations
using System;

class Program
{
    // Main method to execute the program
    static void Main()
    {
        // Get the current date and time
        DateTime currentDateTime = DateTime.Now;  // Retrieve the current system date and time

        // Display the current date and time in the specified format
        Console.WriteLine($"Today is {currentDateTime.Day} of {currentDateTime.ToString("MMMM")} of {currentDateTime.Year}. It´s {currentDateTime.ToString("HH:mm:ss")}");
    }
}