Date And Time - C# Programming Exercise

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.

 Category

Additional Libraries

 Exercise

Date And Time

 Objective

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

 Write Your C# Exercise

// 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")}");
    }
}

 Share this C# exercise

 More C# Programming Exercises of Additional Libraries

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Display directory

    In this exercise, you need to create a program that shows all the files in the current folder. The program should list the files available in the directory where the program...

  •  Display executable files in directory

    In this exercise, you need to create a program that shows the names of all executable files (.com, .exe, .bat, .cmd) in the current folder, excluding the full path. The prog...

  •  Date and time continuous

    In this exercise, you need to create a program that displays the current time in the top-right corner of the screen with the format "HH:mm:ss". The program should pause for ...

  •  Sitemap creator

    In this exercise, you need to create a program that displays the contents of a preliminary "sitemap" on the screen. The sitemap should be generated from the list of "...

  •  List of images as HTML

    In this exercise, you need to create a program that generates an HTML file listing all the images (PNG and JPG files) in the current folder. The program...

  •  System information

    In this exercise, you need to create a program that displays specific system details, including the computer name, domain name, and the username of the current...