DateTimeFormatInfo.YearMonthPattern Property

July 28, 2014

Gets or sets the custom date and time format string for a year and month value, which is associated with the "y" and "Y" standard format strings.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public string YearMonthPattern { get; set; }

Property Value

Type: System.String
The custom format string for a year and month value, which is associated with the "y" and "Y" format strings.

ExceptionCondition
ArgumentNullException

An attempt was made to set the property to null.

InvalidOperationException

The DateTimeFormatInfo object is read-only.

This property is affected if the value of the Calendar property changes.

The following example displays the value of YearMonthPattern for a few cultures.


using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Displays the values of the pattern properties.
      outputBlock.Text += " CULTURE    PROPERTY VALUE" + "\n";
      PrintPattern(outputBlock, "en-US");
      PrintPattern(outputBlock, "ar-EG");
      PrintPattern(outputBlock, "fr-FR");
   }

   public static void PrintPattern(System.Windows.Controls.TextBlock outputBlock, String myCulture)
   {
      DateTimeFormatInfo myDTFI = new CultureInfo(myCulture).DateTimeFormat;
      outputBlock.Text += String.Format("  {0}     {1}", myCulture, myDTFI.YearMonthPattern) + "\n";
   }
}
/*
The example displays the following output:
    CULTURE    PROPERTY VALUE
     en-US     MMMM, yyyy
     ar-EG     MMMM, yyyy
     fr-FR     MMMM yyyy
*/


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft