DateTimeFormatInfo 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供日期和時間值格式的文化特性特定資訊。
public ref class DateTimeFormatInfo sealed : IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider, System::Runtime::Serialization::ISerializable
public sealed class DateTimeFormatInfo : IFormatProvider
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
[System.Serializable]
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider, System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
type DateTimeFormatInfo = class
interface IFormatProvider
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
[<System.Serializable>]
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DateTimeFormatInfo = class
interface ICloneable
interface IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements ICloneable, IFormatProvider
Public NotInheritable Class DateTimeFormatInfo
Implements ICloneable, IFormatProvider, ISerializable
- 繼承
-
DateTimeFormatInfo
- 屬性
- 實作
下列範例會使用反映來取得英文(美國)文化特性 DateTimeFormatInfo 對象的屬性。 它會顯示包含自定義格式字串的屬性值,並使用這些字串來顯示格式化日期。
using System;
using System.Globalization;
using System.Reflection;
public class Example
{
public static void Main()
{
// Get the properties of an en-US DateTimeFormatInfo object.
DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;
Type typ = dtfi.GetType();
PropertyInfo[] props = typ.GetProperties();
DateTime value = new DateTime(2012, 5, 28, 11, 35, 0);
foreach (var prop in props) {
// Is this a format pattern-related property?
if (prop.Name.Contains("Pattern")) {
string fmt = prop.GetValue(dtfi, null).ToString();
Console.WriteLine("{0,-33} {1} \n{2,-37}Example: {3}\n",
prop.Name + ":", fmt, "",
value.ToString(fmt));
}
}
}
}
// The example displays the following output:
// FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt
// Example: Monday, May 28, 2012 11:35:00 AM
//
// LongDatePattern: dddd, MMMM dd, yyyy
// Example: Monday, May 28, 2012
//
// LongTimePattern: h:mm:ss tt
// Example: 11:35:00 AM
//
// MonthDayPattern: MMMM dd
// Example: May 28
//
// RFC1123Pattern: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
// Example: Mon, 28 May 2012 11:35:00 GMT
//
// ShortDatePattern: M/d/yyyy
// Example: 5/28/2012
//
// ShortTimePattern: h:mm tt
// Example: 11:35 AM
//
// SortableDateTimePattern: yyyy'-'MM'-'dd'T'HH':'mm':'ss
// Example: 2012-05-28T11:35:00
//
// UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
// Example: 2012-05-28 11:35:00Z
//
// YearMonthPattern: MMMM, yyyy
// Example: May, 2012
Imports System.Globalization
Imports System.Reflection
Module Example
Public Sub Main()
' Get the properties of an en-US DateTimeFormatInfo object.
Dim dtfi As DateTimeFormatInfo = CultureInfo.GetCultureInfo("en-US").DateTimeFormat
Dim typ As Type = dtfi.GetType()
Dim props() As PropertyInfo = typ.GetProperties()
Dim value As Date = #05/28/2012 11:35AM#
For Each prop In props
' Is this a format pattern-related property?
If prop.Name.Contains("Pattern") Then
Dim fmt As String = CStr(prop.GetValue(dtfi, Nothing))
Console.WriteLine("{0,-33} {1} {2}{3,-37}Example: {4}",
prop.Name + ":", fmt, vbCrLf, "",
value.ToString(fmt))
Console.WriteLine()
End If
Next
End Sub
End Module
' The example displays the following output:
' FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt
' Example: Monday, May 28, 2012 11:35:00 AM
'
' LongDatePattern: dddd, MMMM dd, yyyy
' Example: Monday, May 28, 2012
'
' LongTimePattern: h:mm:ss tt
' Example: 11:35:00 AM
'
' MonthDayPattern: MMMM dd
' Example: May 28
'
' RFC1123Pattern: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
' Example: Mon, 28 May 2012 11:35:00 GMT
'
' ShortDatePattern: M/d/yyyy
' Example: 5/28/2012
'
' ShortTimePattern: h:mm tt
' Example: 11:35 AM
'
' SortableDateTimePattern: yyyy'-'MM'-'dd'T'HH':'mm':'ss
' Example: 2012-05-28T11:35:00
'
' UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
' Example: 2012-05-28 11:35:00Z
'
' YearMonthPattern: MMMM, yyyy
' Example: May, 2012
如需此 API 的詳細資訊,請參閱 DateTimeFormatInfo的補充 API 備註。
Date |
初始化與文化特性無關之 DateTimeFormatInfo 類別的新可寫入實例(不可變)。 |
Abbreviated |
取得或設定類型的一維陣列,String 包含星期幾的文化特性特定縮寫名稱。 |
Abbreviated |
取得或設定與目前 DateTimeFormatInfo 對象相關聯的縮寫月份名稱字串數位。 |
Abbreviated |
取得或設定包含月份特定文化特性縮寫名稱的一維字串數位。 |
AMDesignator |
取得或設定 「ante meridiem」 (中午之前) 的小時字串指示項。 |
Calendar |
取得或設定要用於目前文化特性的行事曆。 |
Calendar |
取得或設定值,指定用來判斷年度第一個日曆周的規則。 |
Current |
取得唯讀 DateTimeFormatInfo 對象,這個物件會根據目前文化特性來格式化值。 |
Date |
取得或設定字串,這個字串會分隔日期的元件,也就是年、月和日。 |
Day |
取得或設定一維字串數位,其中包含星期幾的文化特性特定完整名稱。 |
First |
取得或設定一周的第一天。 |
Full |
取得或設定完整日期和時間值的自定義格式字串。 |
Invariant |
取得與文化特性無關的預設唯讀 DateTimeFormatInfo 物件(不變異)。 |
Is |
取得值,指出 DateTimeFormatInfo 物件是否為唯讀。 |
Long |
取得或設定完整日期值的自定義格式字串。 |
Long |
取得或設定長時間值的自定義格式字串。 |
Month |
取得或設定月份和日值的自定義格式字串。 |
Month |
取得或設定與目前 DateTimeFormatInfo 對象相關聯的月份名稱字串數位。 |
Month |
取得或設定類型的一維陣列,String 包含月份特定文化特性的完整名稱。 |
Native |
取得與目前 DateTimeFormatInfo 對象相關聯的行事曆原生名稱。 |
PMDesignator |
取得或設定 「post meridiem」 (中午之後) 的小時字串指示項。 |
RFC1123Pattern |
取得時間值的自定義格式字串,其以因特網工程任務組 (IETF) 批註要求 (RFC) 1123 規格為基礎。 |
Short |
取得或設定簡短日期值的自定義格式字串。 |
Shortest |
取得或設定與目前 DateTimeFormatInfo 對象相關聯之最短唯一縮寫日名稱的字串數位。 |
Short |
取得或設定短時間值的自定義格式字串。 |
Sortable |
取得可排序日期和時間值的自訂格式字串。 |
Time |
取得或設定字串,這個字串會分隔時間元件,也就是小時、分和秒。 |
Universal |
取得通用、可排序日期和時間字串的自定義格式字串,如 ISO 8601 所定義。 |
Year |
取得或設定年份和月份值的自定義格式字串。 |
ISerializable. |
使用串行化目標物件所需的數據填入 SerializationInfo。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |