當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTimeFormatInfo.CurrentInfo屬性代碼示例

本文整理匯總了C#中System.Globalization.DateTimeFormatInfo.CurrentInfo屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeFormatInfo.CurrentInfo屬性的具體用法?C# DateTimeFormatInfo.CurrentInfo怎麽用?C# DateTimeFormatInfo.CurrentInfo使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在System.Globalization.DateTimeFormatInfo的用法示例。


在下文中一共展示了DateTimeFormatInfo.CurrentInfo屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

//引入命名空間
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      var date = new DateTime(2016, 05, 28, 10, 28, 0);
      var dtfi = DateTimeFormatInfo.CurrentInfo;
      Console.WriteLine("Date and Time Formats for {0:u} in the {1} Culture:\n", 
                        date, CultureInfo.CurrentCulture.Name); 

      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Long Date Pattern", 
                        dtfi.LongDatePattern, 
                        date.ToString(dtfi.LongDatePattern));
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Long Time Pattern", 
                        dtfi.LongTimePattern, 
                        date.ToString(dtfi.LongTimePattern));
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Month/Day Pattern", 
                        dtfi.MonthDayPattern, 
                        date.ToString(dtfi.MonthDayPattern));
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Short Date Pattern", 
                        dtfi.ShortDatePattern, 
                        date.ToString(dtfi.ShortDatePattern));
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Short Time Pattern", 
                        dtfi.ShortTimePattern, 
                        date.ToString(dtfi.ShortTimePattern));
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Year/Month Pattern", 
                        dtfi.YearMonthPattern, 
                        date.ToString(dtfi.YearMonthPattern));
   }
}
開發者ID:.NET開發者,項目名稱:System.Globalization,代碼行數:33,代碼來源:DateTimeFormatInfo.CurrentInfo

輸出:

Date and Time Formats for 2016-05-28 10:28:00Z in the en-US Culture:

Long Date Pattern      dddd, MMMM d, yyyy   Saturday, May 28, 2016
Long Time Pattern      h:mm:ss tt           10:28:00 AM
Month/Day Pattern      MMMM d               May 28
Short Date Pattern     M/d/yyyy             5/28/2016
Short Time Pattern     h:mm tt              10:28 AM
Year/Month Pattern     MMMM yyyy            May 2016

示例2: Main

//引入命名空間
using System;
using System.Globalization;

class Class1 {
  static void Main(string[] args) {
         CultureInfo MyCulture = new CultureInfo("es-ES");
         DateTimeFormatInfo Myfmt;
         DateTimeFormatInfo fmt1;

         Myfmt = MyCulture.DateTimeFormat;
         fmt1  = DateTimeFormatInfo.CurrentInfo;

         Console.WriteLine(Myfmt.GetMonthName(12));
         Console.WriteLine(fmt1.GetMonthName(12));
      }
}
開發者ID:C#程序員,項目名稱:System.Globalization,代碼行數:17,代碼來源:DateTimeFormatInfo.CurrentInfo


注:本文中的System.Globalization.DateTimeFormatInfo.CurrentInfo屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。