using System; class Program { static void Main(string[] args) { // Retrieve current date and time DateTime currentDateTime = System.DateTime.Now; // Display current date and time in console Console.WriteLine("Current Date and Time: " + currentDateTime); } }
using System; class Program { static void Main(string[] args) { // Retrieve current date and time DateTime currentDateTime = System.DateTime.Now; // Display current date and time in a specific format Console.WriteLine("Current Date and Time: " + currentDateTime.ToString("yyyy/MM/dd HH:mm:ss")); } }In this example, we retrieve the current date and time and display it in a specific format using the ToString method. The format we're using is "yyyy/MM/dd HH:mm:ss", which displays the year, month, day, hour, minute, and second. Package library: This method is a part of the .NET Framework, which is a package library that provides a comprehensive set of classes and functions for building applications.