DateTimeFormatInfo 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供有关日期和时间值格式的区域性特定信息。
public ref class DateTimeFormatInfo sealed : IFormatProviderpublic ref class DateTimeFormatInfo sealed : ICloneable, IFormatProviderpublic ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider, System::Runtime::Serialization::ISerializablepublic sealed class DateTimeFormatInfo : IFormatProviderpublic 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, IFormatProvidertype DateTimeFormatInfo = class
    interface IFormatProvidertype 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 IFormatProviderPublic NotInheritable Class DateTimeFormatInfo
Implements IFormatProviderPublic NotInheritable Class DateTimeFormatInfo
Implements ICloneable, IFormatProviderPublic 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 备注。
构造函数
| DateTimeFormatInfo() | 初始化与区域性无关(固定)的 DateTimeFormatInfo 类的新可写实例。 | 
属性
| AbbreviatedDayNames | 获取或设置一维数组,该数组的类型为 String 包含一周中日期的区域性特定的缩写名称。 | 
| AbbreviatedMonthGenitiveNames | 获取或设置与当前 DateTimeFormatInfo 对象关联的缩写月份名称的字符串数组。 | 
| AbbreviatedMonthNames | 获取或设置一维字符串数组,该数组包含特定于区域性的月份缩写名称。 | 
| AMDesignator | 获取或设置“ante meridiem”(中午前)的小时字符串设计器。 | 
| Calendar | 获取或设置要用于当前区域性的日历。 | 
| CalendarWeekRule | 获取或设置一个值,该值指定用于确定年份的第一个日历周的规则。 | 
| CurrentInfo | 获取一个只读 DateTimeFormatInfo 对象,该对象基于当前区域性设置值的格式。 | 
| DateSeparator | 获取或设置分隔日期的组件(即年、月和日)的字符串。 | 
| DayNames | 获取或设置一维字符串数组,该数组包含一周中特定于区域性的全名。 | 
| FirstDayOfWeek | 获取或设置一周的第一天。 | 
| FullDateTimePattern | 获取或设置长日期和长时间值的自定义格式字符串。 | 
| InvariantInfo | 获取与区域性无关(固定)的默认只读 DateTimeFormatInfo 对象。 | 
| IsReadOnly | 获取一个值,该值指示 DateTimeFormatInfo 对象是否为只读。 | 
| LongDatePattern | 获取或设置长日期值的自定义格式字符串。 | 
| LongTimePattern | 获取或设置较长时间值的自定义格式字符串。 | 
| MonthDayPattern | 获取或设置月份和日期值的自定义格式字符串。 | 
| MonthGenitiveNames | 获取或设置与当前 DateTimeFormatInfo 对象关联的月份名称的字符串数组。 | 
| MonthNames | 获取或设置一维数组,该数组的类型为 String 包含月区域性特定的全名。 | 
| NativeCalendarName | 获取与当前 DateTimeFormatInfo 对象关联的日历的本机名称。 | 
| PMDesignator | 获取或设置“post meridiem”(中午后)的小时字符串设计器。 | 
| RFC1123Pattern | 获取基于 Internet 工程工作队(IETF)注释请求(RFC)1123 规范的时间值的自定义格式字符串。 | 
| ShortDatePattern | 获取或设置短日期值的自定义格式字符串。 | 
| ShortestDayNames | 获取或设置与当前 DateTimeFormatInfo 对象关联的最短唯一缩写日期名称的字符串数组。 | 
| ShortTimePattern | 获取或设置短时间值的自定义格式字符串。 | 
| SortableDateTimePattern | 获取可排序日期和时间值的自定义格式字符串。 | 
| TimeSeparator | 获取或设置分隔时间组件(即小时、分钟和秒)的字符串。 | 
| UniversalSortableDateTimePattern | 获取 ISO 8601 定义的通用、可排序日期和时间字符串的自定义格式字符串。 | 
| YearMonthPattern | 获取或设置一年和月份值的自定义格式字符串。 | 
方法
显式接口实现
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) | 使用序列化目标对象所需的数据填充 SerializationInfo。 |