Q:

Write a C# Sharp program to use each of the standard date time format strings to display the string representation of a date and time for four different cultures

0

Write a C# Sharp program to use each of the standard date time format strings to display the string representation of a date and time for four different cultures. 

Expected Output :

d Format Specifier      zh-HK Culture                               16/10/2015   
d Format Specifier      en-US Culture                               10/16/2015   
d Format Specifier      es-ES Culture                               16/10/2015   
d Format Specifier      fr-CA Culture                               2015-10-16   
                                                                                 
D Format Specifier      zh-HK Culture                              2015年10月16日   
D Format Specifier      en-US Culture                 Friday, October 16, 2015   
D Format Specifier      es-ES Culture           viernes, 16 de octubre de 2015   
D Format Specifier      fr-CA Culture                          16 octobre 2015

All Answers

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

using System;
using System.Globalization;

public class Example39
{
   public static void Main()
   {
      // Create an array of all supported standard date and time format specifiers.
      string[] formats = {"d", "D", "f", "F", "g", "G", "m", "o", "r", 
                          "s", "t", "T", "u", "U", "Y"};
      // Create an array of four cultures.                                 
      CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("zh-HK"), 
                                CultureInfo.CreateSpecificCulture("en-US"), 
                                CultureInfo.CreateSpecificCulture("es-GB"), 
                                CultureInfo.CreateSpecificCulture("fr-CA")};
       // Define date to be displayed.
      DateTime dateToDisplay = new DateTime(2015, 10, 16, 17, 4, 32);

      // Iterate each standard format specifier.
      foreach (string formatSpecifier in formats)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0} Format Specifier {1, 10} Culture {2, 40}", 
                              formatSpecifier, culture.Name, 
                              dateToDisplay.ToString(formatSpecifier, culture));
         Console.WriteLine();
      }   
   }
}

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