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

  • برمجة
  • برمجة سي شارب

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

الأجوبة

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();
      }   
   }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...