DateTimeFormatInfo.AbbreviatedMonthNames 属性

定义

获取或设置一维字符串数组,它包含各月的特定于区域性的缩写名称。

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

属性值

String[]

一个具有 13 个元素的一维字符串数组,它包含各月的特定于区域性的缩写名称。 对于 12 个月的日历,数组的第 13 个元素是一个空字符串。 InvariantInfo 数组包含"Jan"、"Feb"、"Mar"、"Apr"、"May"、"Jun"、"Jul"、"Aug"、"Sep"、"Oct"、"Nov"、"Dec"和""。

例外

该属性设置为 null

该属性正被设置为多维数组或者长度不是正好为 13 的数组。

设置了该属性,但 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

注解

如果设置此属性,数组必须是一维的,且正好包含 13 个元素。 Calendar 对象适合包含 13 个月的日历。 索引为零处的元素 (第一个元素) 表示 属性 Calendar 定义的一年中的第一个月。

如果设置 属性 AbbreviatedMonthNames ,还必须设置 属性 AbbreviatedMonthGenitiveNamesAbbreviatedMonthNamesAbbreviatedMonthGenitiveNames 属性用于使用以下格式字符串设置日期格式:

  • 标准日期和时间格式字符串,对包含“MMM”格式说明符的自定义格式字符串进行别名化。

  • 包含“MMM”格式说明符的自定义日期和时间格式字符串。

如果属性的值 Calendar 发生更改,则此属性将受到影响。 如果选定的 Calendar 不支持缩写月份名称,则数组将包含完整的月份名称。

适用于

另请参阅