w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Retrieve the current date


C# Sharp DateTime : Exercise-8 with Solution

Write a C# Sharp program to retrieve the current date.

Expected Output :

General format 8/20/2016 12:00:00 AM                                    
Display the date in a variety of formats:                               
8/20/2016                                                               
Saturday, August 20, 2016                                               
8/20/2016 12:00 AM  

C# Sharp Code:

 using System;

public class Example8
{
   public static void Main()
   {
      // Get the current date.
      DateTime thisDay = DateTime.Today;
      Console.WriteLine("General format " +thisDay.ToString());
      Console.WriteLine("Display the date in a variety of formats: ");
      Console.WriteLine(thisDay.ToString("d"));
      Console.WriteLine(thisDay.ToString("D"));
      Console.WriteLine(thisDay.ToString("g"));
   }
}

C# Sharp Practice online:

using System;

public class Example8
{
   public static void Main()
   {
      // Get the current date.
      DateTime thisDay = DateTime.Today;
      Console.WriteLine("General format " +thisDay.ToString());
      Console.WriteLine("Display the date in a variety of formats: ");
      Console.WriteLine(thisDay.ToString("d"));
      Console.WriteLine(thisDay.ToString("D"));
      Console.WriteLine(thisDay.ToString("g"));
   }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program