DateTimeFormatInfo.CurrentInfo 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得根據目前文化特性格式化值的唯讀 DateTimeFormatInfo 物件。
public:
static property System::Globalization::DateTimeFormatInfo ^ CurrentInfo { System::Globalization::DateTimeFormatInfo ^ get(); };
public static System.Globalization.DateTimeFormatInfo CurrentInfo { get; }
static member CurrentInfo : System.Globalization.DateTimeFormatInfo
Public Shared ReadOnly Property CurrentInfo As 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 回的物件會反映使用者覆寫。