w3resource

C# Sharp Exercises: Retrieve the current date

C# Sharp DateTime: Exercise-8 with Solution

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

Sample Solution:-

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

Sample Output:

General format 6/10/2017 12:00:00 AM                                                                          
Display the date in a variety of formats:                                                                     
6/10/2017                                                                                                     
Saturday, June 10, 2017                                                                                       
6/10/2017 12:00 AM 

Flowchart :

Flowchart: C# Sharp Exercises - Retrieve the current date

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to get the time of day from a given array of date time values.
Next: Write a C# Sharp program to calculate what day of the week is 40 days from this moment.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter