Q:

Write a C# Sharp program to extract the Date property and display the DateTime value in the formatted output

0

Write a C# Sharp program to extract the Date property and display the DateTime value in the formatted output. 

Expected 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 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now