DateTimeFormatInfo.MonthDayPattern 属性

定义

获取或设置月份和日期值的自定义格式字符串。

public:
 property System::String ^ MonthDayPattern { System::String ^ get(); void set(System::String ^ value); };
public string MonthDayPattern { get; set; }
member this.MonthDayPattern : string with get, set
Public Property MonthDayPattern As String

属性值

月份和日期值的自定义格式字符串。

例外

该属性设置为 null

设置了该属性,但 DateTimeFormatInfo 对象为只读。

示例

以下示例显示几个区域性的 的值 MonthDayPattern

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->MonthDayPattern );
}

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 dd
ja-JP     M'?'d'?'
fr-FR     d MMMM

*/
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.MonthDayPattern );
   }
}

/*
This code produces the following output.  The question marks take the place of native script characters.

 CULTURE    PROPERTY VALUE
  en-US     MMMM dd
  ja-JP     M'?'d'?'
  fr-FR     d MMMM

*/
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.MonthDayPattern)

   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 dd
'  ja-JP     M'?'d'?'
'  fr-FR     d MMMM
'

注解

属性 MonthDayPattern 定义通过调用 DateTime.ToStringDateTimeOffset.ToString 方法以及提供“m”和“M”标准格式字符串的复合格式字符串返回的日期字符串的区域性特定格式。

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

建议将月份和日期模式中的日期分隔符设置为确切的字符串,而不是使用日期分隔符占位符。 例如,若要获取模式 MM-DD,请将月份和日期模式设置为“MM-DD”。

适用于

另请参阅