C# Sharp Exercises: Display the DateTime value in the formatted output
C# Sharp DateTime: Exercise-1 with Solution
Write a C# Sharp program to extract the Date property and display the DateTime value in the formatted output.
Sample Solution:-
C# Sharp Code:
using System;
public class Example1
{
public static void Main()
{
DateTime dt1 = new DateTime(2016, 6, 8, 11, 49, 0);
Console.WriteLine("Complete date: "+dt1.ToString());
// Get date-only portion of date, without its time.
DateTime dateOnly = dt1.Date;
Console.WriteLine("Short Date: "+dateOnly.ToString("d"));
Console.WriteLine("Display date using 24-hour clock format:");
Console.WriteLine(dateOnly.ToString("g"));
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"));
}
}
Sample Output:
Complete date: 6/8/2016 11:49:00 AM Short Date: 6/8/2016 Display date using 24-hour clock format: 6/8/2016 12:00 AM 06/08/2016 00:00
Flowchart :

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: C# Sharp DateTime Exercises.
Next: Write a C# Sharp program to display the Day properties (year, month, day, hour, minute, second, millisecond etc.).
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion