DateTimeFormatInfo.YearMonthPattern プロパティ

定義

年と月の値のカスタム書式指定文字列を取得または設定します。

C#
public string YearMonthPattern { get; set; }

プロパティ値

年と月の値のカスタム書式指定文字列。

例外

プロパティが null に設定されています。

このプロパティが設定されていますが、DateTimeFormatInfo オブジェクトは読み取り専用です。

次の例では、いくつかのカルチャの の YearMonthPattern 値を表示します。

C#
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

*/

注釈

プロパティはYearMonthPattern、 メソッドと DateTimeOffset.ToString メソッドの呼び出しDateTime.ToString、および "y" および "Y" 標準書式指定文字列が提供される複合書式指定文字列によって返される日付文字列のカルチャ固有の形式を定義します。

このプロパティは、プロパティの値が変更された場合に影響を Calendar 受けます。

日付区切り記号プレースホルダーを使用する代わりに、年月パターンの日付区切り記号を正確な文字列に設定することをお勧めします。 たとえば、MM-yyyy パターンを取得するには、年月パターンを "MM-yyyy" に設定します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

こちらもご覧ください