共用方式為


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-yyyyy模式,請將年份月份模式設定為 「MM-yyyy」。。

適用於

另請參閱