DateTimeFormatInfo.CurrentInfo 屬性

定義

取得根據目前文化特性格式化值的唯讀 DateTimeFormatInfo 物件。

public:
 static property System::Globalization::DateTimeFormatInfo ^ CurrentInfo { System::Globalization::DateTimeFormatInfo ^ get(); };
public static System.Globalization.DateTimeFormatInfo CurrentInfo { get; }
member this.CurrentInfo : System.Globalization.DateTimeFormatInfo
Public Shared ReadOnly Property CurrentInfo As DateTimeFormatInfo

屬性值

DateTimeFormatInfo

唯讀 DateTimeFormatInfo 物件,根據的是目前執行緒的 CultureInfo 物件。

範例

下列範例 CurrentInfo 會使用屬性來抓取 DateTimeFormatInfo 物件,此物件代表目前文化特性的格式化慣例,在此案例中為 en-us 文化特性。 然後,它會顯示六個格式化屬性的格式字串和結果字串。

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));
   }
}
// The example displays the following output:
//    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
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim dat As New Date(2016, 05, 28, 10, 28, 0)
      Dim dtfi As DateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo
      Console.WriteLine("Date and Time Formats for {0:u} in the {1} Culture:", 
                        dat, CultureInfo.CurrentCulture.Name) 
      Console.WriteLine()
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Long Date Pattern", 
                        dtfi.LongDatePattern, 
                        dat.ToString(dtfi.LongDatePattern))
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Long Time Pattern", 
                        dtfi.LongTimePattern, 
                        dat.ToString(dtfi.LongTimePattern))
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Month/Day Pattern", 
                        dtfi.MonthDayPattern, 
                        dat.ToString(dtfi.MonthDayPattern))
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Short Date Pattern", 
                        dtfi.ShortDatePattern, 
                        dat.ToString(dtfi.ShortDatePattern))
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Short Time Pattern", 
                        dtfi.ShortTimePattern, 
                        dat.ToString(dtfi.ShortTimePattern))
      Console.WriteLine("{0,-22} {1,-20} {2,-30}", "Year/Month Pattern", 
                        dtfi.YearMonthPattern, 
                        dat.ToString(dtfi.YearMonthPattern))
   End Sub
End Module
' The example displays the following output:
'    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

備註

DateTimeFormatInfo由屬性傳回的物件會 CurrentInfo 反映使用者覆寫。

適用於

另請參閱