Freigeben über


DateTimeFormatInfo.YearMonthPattern Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Property YearMonthPattern As String
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.

Exceptions

Exception Condition
ArgumentNullException

An attempt was made to set the property to nulla null reference (Nothing in Visual Basic).

InvalidOperationException

The DateTimeFormatInfo object is read-only.

Remarks

See Custom Date and Time Format Strings for custom format specifiers that can be combined to form custom format strings such as "yyyy MMMM".

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

Examples

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

Imports System.Globalization

Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Displays the values of the pattern properties.
      outputBlock.Text &= " CULTURE    PROPERTY VALUE" & vbCrLf
      PrintPattern(outputBlock, "en-US")
      PrintPattern(outputBlock, "ar-EG")
      PrintPattern(outputBlock, "fr-FR")
   End Sub 

   Public Shared Sub PrintPattern(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal myCulture As [String])
      Dim myDTFI As DateTimeFormatInfo = New CultureInfo(myCulture).DateTimeFormat
      outputBlock.Text += String.Format("  {0}     {1}", myCulture, myDTFI.YearMonthPattern) & vbCrLf
   End Sub 
End Class 
' This example displays the following output:
'        CULTURE    PROPERTY VALUE
'         en-US     MMMM, yyyy
'         ar-EG     MMMM, yyyy
'         fr-FR     MMMM yyyy
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
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.