Q:

Write a C# Sharp program to convert the value of the current DateTime object to its equivalent short date string representation

0

Write a C# Sharp program to convert the value of the current DateTime object to its equivalent short date string representation.

Expected Output :

Displaying short date for en-NZ culture:                                         
   17/08/2016 (Short Date String)                                                
   17/08/2016 ('d' standard format specifier)                                    
                                                                                 
Displaying short date for fi-FI culture:                                         
   17.8.2016                     

All Answers

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

using System;
using System.Globalization;
using System.Threading;

public class Example34
{
   public static void Main()
   {
      DateTime dateToDisplay = new DateTime(2016, 8, 17, 8, 42, 50);
      CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
      // Change culture to en-NZ.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("en-NZ");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0} (Short Date String)", 
                        dateToDisplay.ToShortDateString());
      // Display using 'd' standard format specifier to illustrate it is
      // identical to the string returned by ToShortDateString.
      Console.WriteLine("   {0} ('d' standard format specifier)", 
                        dateToDisplay.ToString("d"));
      Console.WriteLine();

      // Change culture to fi-FI.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("fi-FI");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString());
      Console.WriteLine();

      // Change culture to de-CH.    
      Thread.CurrentThread.CurrentCulture = new CultureInfo("de-CH");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString());

      // Restore original culture.
      Thread.CurrentThread.CurrentCulture = originalCulture;
   }
}

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