DateTimeFormatInfo.YearMonthPattern 属性

定义

获取或设置年份和月份值的自定义格式字符串。

public:
 property System::String ^ YearMonthPattern { System::String ^ get(); void set(System::String ^ value); };
public string YearMonthPattern { get; set; }
member this.YearMonthPattern : string with get, set
Public Property YearMonthPattern As String

属性值

年份和月份值的自定义格式字符串。

例外

该属性设置为 null

设置了该属性,但 DateTimeFormatInfo 对象为只读。

示例

以下示例显示几个区域性的 的值 YearMonthPattern

using namespace System;
using namespace System::Globalization;
void PrintPattern( String^ myCulture )
{
   CultureInfo^ MyCI = gcnew CultureInfo( myCulture,false );
   DateTimeFormatInfo^ myDTFI = MyCI->DateTimeFormat;
   Console::WriteLine( " {0} {1}", myCulture, myDTFI->YearMonthPattern );
}

int main()
{

   // Displays the values of the pattern properties.
   Console::WriteLine( " CULTURE    PROPERTY VALUE" );
   PrintPattern( "en-US" );
   PrintPattern( "ja-JP" );
   PrintPattern( "fr-FR" );
}

/*
This code produces the following output.  The question marks take the place of native script characters.

 CULTURE    PROPERTY VALUE
  en-US     MMMM yyyy
  ja-JP     yyyy年M月
  fr-FR     MMMM yyyy

*/
using System;
using System.Globalization;

public class SamplesDTFI  {

   public static void Main()  {

      // Displays the values of the pattern properties.
      Console.WriteLine( " CULTURE    PROPERTY VALUE" );
      PrintPattern( "en-US" );
      PrintPattern( "ja-JP" );
      PrintPattern( "fr-FR" );
   }

   public static void PrintPattern( String myCulture )  {

      DateTimeFormatInfo myDTFI = new CultureInfo( myCulture, false ).DateTimeFormat;
      Console.WriteLine( "  {0}     {1}", myCulture, myDTFI.YearMonthPattern );
   }
}

/*
This code produces the following output.  The question marks take the place of native script characters.

 CULTURE    PROPERTY VALUE
  en-US     MMMM yyyy
  ja-JP     yyyy年M月
  fr-FR     MMMM yyyy

*/
Imports System.Globalization

Public Class SamplesDTFI

   Public Shared Sub Main()

      ' Displays the values of the pattern properties.
      Console.WriteLine(" CULTURE    PROPERTY VALUE")
      PrintPattern("en-US")
      PrintPattern("ja-JP")
      PrintPattern("fr-FR")

   End Sub

   Public Shared Sub PrintPattern(myCulture As [String])

      Dim myDTFI As DateTimeFormatInfo = New CultureInfo(myCulture, False).DateTimeFormat
      Console.WriteLine("  {0}     {1}", myCulture, myDTFI.YearMonthPattern)

   End Sub

End Class

'This code produces the following output.  The question marks take the place of native script characters.
'
' CULTURE    PROPERTY VALUE
'  en-US     MMMM yyyy
'  ja-JP     yyyy年M月
'  fr-FR     MMMM yyyy
'

注解

属性 YearMonthPattern 定义通过调用 DateTime.ToStringDateTimeOffset.ToString 方法以及提供“y”和“Y”标准格式字符串的复合格式字符串返回的日期字符串的区域性特定格式。

如果属性的值 Calendar 发生更改,则此属性将受到影响。

建议将年份月份模式中的日期分隔符设置为确切的字符串,而不是使用日期分隔符占位符。 例如,若要获取模式 MM-yyyy,请将年月模式设置为“MM-yyyy”。

适用于

另请参阅