Write a C# Sharp program to display the string representation of a date and time using CultureInfo objects that represent five different cultures

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

Write a C# Sharp program to display the string representation of a date and time using CultureInfo objects that represent five different cultures. 

Expected Output :

In Invariant Language (Invariant Country), 05/17/2016 09:00:00                   
In en-ZA, 2016-05-17 09:00:00 AM                                                 
In ko-KR, 2016-05-17 오전 9:00:00                                                  
In de-DE, 17.05.2016 09:00:00                                                    
In es-ES, 17/05/2016 9:00:00                                                     
In en-US, 5/17/2016 9:00:00 AM 

الأجوبة

using System;
using System.Globalization;

public class Example37
{
   public static void Main()
   {
      CultureInfo[] cultures = new CultureInfo[] {CultureInfo.InvariantCulture, 
                                                  new CultureInfo("en-ZA"), 
                                                  new CultureInfo("ko-KR"), 
                                                  new CultureInfo("de-DE"), 
                                                  new CultureInfo("es-ES"),
                                                  new CultureInfo("en-US")};

      DateTime thisDate = new DateTime(2016, 5, 17, 9, 0, 0);                                            

      foreach (CultureInfo culture in cultures)
      {
         string cultureName; 
         if (string.IsNullOrEmpty(culture.Name))
            cultureName = culture.NativeName;
         else
            cultureName = culture.Name;

         Console.WriteLine("In {0}, {1}", 
                           cultureName, thisDate.ToString(culture));
      }                                            
      }
}
هل كان المحتوى مفيد؟

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

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