DateTimeFormatInfo.AbbreviatedMonthGenitiveNames 属性

定义

获取或设置与当前 DateTimeFormatInfo 对象关联的月份缩写名称的字符串数组。

public:
 property cli::array <System::String ^> ^ AbbreviatedMonthGenitiveNames { cli::array <System::String ^> ^ get(); void set(cli::array <System::String ^> ^ value); };
public string[] AbbreviatedMonthGenitiveNames { get; set; }
[System.Runtime.InteropServices.ComVisible(false)]
public string[] AbbreviatedMonthGenitiveNames { get; set; }
member this.AbbreviatedMonthGenitiveNames : string[] with get, set
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.AbbreviatedMonthGenitiveNames : string[] with get, set
Public Property AbbreviatedMonthGenitiveNames As String()

属性值

String[]

月份缩写名称的数组。

属性

例外

在设置操作中,该数组是多维数组或者长度不是正好为 13 的数组。

在设置操作中,数组或数组的其中一个元素为 null

在设置操作中,当前的 DateTimeFormatInfo 对象是只读的。

示例

以下示例创建一个读/写CultureInfo对象,该对象表示英语 (美国) 区域性,并将缩写的元月名称分配给其 AbbreviatedMonthNamesAbbreviatedMonthGenitiveNames 属性。 然后,它显示日期的字符串表示形式,其中包括区域性支持的日历中每个月的缩写月份名称。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo ci = CultureInfo.CreateSpecificCulture("en-US");
      DateTimeFormatInfo dtfi = ci.DateTimeFormat;
      dtfi.AbbreviatedMonthNames = new string[] { "of Jan", "of Feb", "of Mar",
                                                  "of Apr", "of May", "of Jun",
                                                  "of Jul", "of Aug", "of Sep",
                                                  "of Oct", "of Nov", "of Dec", "" };
      dtfi.AbbreviatedMonthGenitiveNames = dtfi.AbbreviatedMonthNames;
      DateTime dat = new DateTime(2012, 5, 28);

      for (int ctr = 0; ctr < dtfi.Calendar.GetMonthsInYear(dat.Year); ctr++)
         Console.WriteLine(dat.AddMonths(ctr).ToString("dd MMM yyyy", dtfi));
   }
}
// The example displays the following output:
//       28 of May 2012
//       28 of Jun 2012
//       28 of Jul 2012
//       28 of Aug 2012
//       28 of Sep 2012
//       28 of Oct 2012
//       28 of Nov 2012
//       28 of Dec 2012
//       28 of Jan 2013
//       28 of Feb 2013
//       28 of Mar 2013
//       28 of Apr 2013
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
      Dim dtfi As DateTimeFormatInfo = ci.DateTimeFormat
      dtfi.AbbreviatedMonthNames = { "of Jan", "of Feb", "of Mar", 
                                     "of Apr", "of May", "of Jun", 
                                     "of Jul", "of Aug", "of Sep", 
                                     "of Oct", "of Nov", "of Dec", "" }  
      dtfi.AbbreviatedMonthGenitiveNames = dtfi.AbbreviatedMonthNames
      Dim dat As Date = #05/28/2012#
      
      For ctr As Integer = 0 To dtfi.Calendar.GetMonthsInYear(dat.Year) - 1
         Console.WriteLine(dat.AddMonths(ctr).ToString("dd MMM yyyy", dtfi))
      Next
   End Sub
End Module
' The example displays the following output:
'       28 of May 2012
'       28 of Jun 2012
'       28 of Jul 2012
'       28 of Aug 2012
'       28 of Sep 2012
'       28 of Oct 2012
'       28 of Nov 2012
'       28 of Dec 2012
'       28 of Jan 2013
'       28 of Feb 2013
'       28 of Mar 2013
'       28 of Apr 2013

注解

在某些语言中,作为日期一部分的月份名称显示在一个词条中。 例如,ru-RU 或俄语 (俄罗斯) 区域性中的日期由日期编号和天生月份名称组成,例如 1 Января (1 月 1 日) 。 对于这些区域性,如果自定义格式字符串包含“MMM”格式说明符, DateTime.ToString 则 或 ToString 方法包括数组的适当 AbbreviatedMonthGenitiveNames 成员,以取代结果字符串中的“MMM”。

在设置操作中,数组必须是一维的,只有 13 个元素,因为 Calendar 对象可容纳具有 13 个月的日历。 对于具有 12 个月的日历,第 13 个元素应为 String.Empty。 (索引为 0 的元素的第一个元素) 表示 属性 Calendar 定义的一年中的第一个月。

如果设置 AbbreviatedMonthGenitiveNames 属性,还必须设置 AbbreviatedMonthNames 属性。

适用于

另请参阅