DateTimeFormatInfo.YearMonthPattern 属性

获取或设置年份和月份值的格式模式,该格式模式与“y”和“Y”格式字符关联。

**命名空间:**System.Globalization
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Property YearMonthPattern As String
用法
Dim instance As DateTimeFormatInfo
Dim value As String

value = instance.YearMonthPattern

instance.YearMonthPattern = value
public string YearMonthPattern { get; set; }
public:
property String^ YearMonthPattern {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_YearMonthPattern ()

/** @property */
public void set_YearMonthPattern (String value)
public function get YearMonthPattern () : String

public function set YearMonthPattern (value : String)

属性值

年份和月份值的格式模式,该格式模式与“y”和“Y”格式字符关联。

异常

异常类型 条件

ArgumentNullException

该属性被设置为 空引用(在 Visual Basic 中为 Nothing)。

InvalidOperationException

设置该属性,并且 DateTimeFormatInfo 是只读的。

备注

请参见 DateTimeFormatInfo 以了解可被合并以构造自定义模式的模式;例如“yyyy MMMM”。

如果 Calendar 属性的值发生改变,则该属性将受到影响。

示例

下面的代码示例显示几个区域性的 YearMonthPattern 的值。

Imports System
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 'Main

   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 'PrintPattern 

End Class 'SamplesDTFI

'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

*/
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

*/
import System.* ;
import System.Globalization.* ;

public class SamplesDTFI
{
    public static void main(String[] args)
    {
        // Displays the values of the pattern properties.
        Console.WriteLine(" CULTURE    PROPERTY VALUE");
        PrintPattern("en-US");
        PrintPattern("ja-JP");
        PrintPattern("fr-FR");
    } //main

    public static void PrintPattern(String myCulture)
    {
        DateTimeFormatInfo myDTFI = 
            (new CultureInfo(myCulture, false)).get_DateTimeFormat();

        Console.WriteLine("  {0}     {1}", myCulture, 
            myDTFI.get_YearMonthPattern());
    } //PrintPattern 
} //SamplesDTFI

/*
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
*/

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DateTimeFormatInfo 类
DateTimeFormatInfo 成员
System.Globalization 命名空间