DateTimeFormatInfo.YearMonthPattern 屬性

定義

取得或設定年月值的自訂格式字串。Gets or sets the custom format string for a year and month value.

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

屬性值

年份和月份值的自訂格式字串。The custom format string for a year and month value.

例外狀況

正在將屬性設定為 nullThe property is being set to null.

正在設定屬性,而且 DateTimeFormatInfo 物件為唯讀。The property is being set and the DateTimeFormatInfo object is read-only.

範例

下列範例會顯示一些文化特性YearMonthPattern的值。The following example displays the value of YearMonthPattern for a few cultures.

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
'

備註

屬性會定義日期字串的特定文化特性格式,其由呼叫DateTime.ToStringDateTimeOffset.ToString方法,以及提供「y」和「y」標準格式字串的複合格式字串所傳回。 YearMonthPatternThe YearMonthPattern property defines the culture-specific format of date strings that are returned by calls to the DateTime.ToString and DateTimeOffset.ToString methods and by composite format strings that are supplied the "y" and "Y" standard format strings.

如果Calendar屬性的值變更,這個屬性會受到影響。This property is affected if the value of the Calendar property changes.

我們建議您將 [年月] 模式中的日期分隔符號設定為確切的字串,而不是使用 [日期分隔符號] 預留位置。We recommend that you set the date separator in the year month pattern to an exact string instead of using the date separator placeholder. 例如,若要取得模式 MM-yyyy,請將 year 月份模式設定為 "MM-yyyy"。For example, to get the pattern MM-yyyy, set the year month pattern to "MM-yyyy".

適用於

另請參閱