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

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

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

Expected Output :

Current culture: en-CA                                                           
Date: 2016-08-17 10:30:15 AM                                                     
Long time pattern: 'h:mm:ss tt'                                                  
Long time with format string:     10:30:15 AM                                    
Long time with ToLongTimeString:  10:30:15 AM 

الأجوبة

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

public class Example33
{
   public static void Main() 
   {
      // Create an array of culture names.
      String[] names = { "en-CA", "en-AU", "fr-CH", "de-AT" };
      // Initialize a DateTime object.
      DateTime dateValue = new System.DateTime(2016, 8, 17, 10, 30, 15);

      // Iterate the array of culture names.
      foreach (var name in names) {
         // Change the culture of the current thread.
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(name);
         // Display the name of the current culture and the date.
         Console.WriteLine("Current culture: {0}", CultureInfo.CurrentCulture.Name);
         Console.WriteLine("Date: {0:G}", dateValue);        

         // Display the long time pattern and the long time.
         Console.WriteLine("Long time pattern: '{0}'", 
                           DateTimeFormatInfo.CurrentInfo.LongTimePattern);
         Console.WriteLine("Long time with format string:     {0:T}", dateValue);
         Console.WriteLine("Long time with ToLongTimeString:  {0}\n", 
                           dateValue.ToLongTimeString());
      }
   }
}
هل كان المحتوى مفيد؟

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

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