DateTimeFormatInfo.YearMonthPattern Propriété
Définition
Obtient ou définit la chaîne de format personnalisée pour une valeur d'année et de mois.Gets or sets the custom format string for a year and month value.
public:
property System::String ^ YearMonthPattern { System::String ^ get(); void set(System::String ^ value); };
public string YearMonthPattern { get; set; }
member this.YearMonthPattern : string with get, set
Public Property YearMonthPattern As String
Valeur de propriété
Chaîne de format personnalisée pour une valeur d'année et de mois.The custom format string for a year and month value.
Exceptions
La propriété est définie sur null
.The property is being set to null
.
La propriété est définie et l’objet DateTimeFormatInfo est en lecture seule.The property is being set and the DateTimeFormatInfo object is read-only.
Exemples
L’exemple suivant affiche la valeur de YearMonthPattern pour quelques cultures.The following example displays the value of YearMonthPattern for a few cultures.
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
*/
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
*/
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.YearMonthPattern)
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, yyyy
' ja-JP yyyy'?'M'?'
' fr-FR MMMM yyyy
'
Remarques
La YearMonthPattern propriété définit le format spécifique à la culture des chaînes de date qui sont retournées par les appels aux DateTime.ToString DateTimeOffset.ToString méthodes et et les chaînes de format composites qui sont fournies avec les chaînes de format standard "y" et "y".The YearMonthPattern property defines the culture-specific format of date strings that are returned by calls to the DateTime.ToString and DateTimeOffset.ToString methods and by composite format strings that are supplied the "y" and "Y" standard format strings.
Cette propriété est affectée si la valeur de la Calendar propriété change.This property is affected if the value of the Calendar property changes.
Nous vous recommandons de définir le séparateur de date dans le modèle année mois sur une chaîne exacte au lieu d’utiliser l’espace réservé de séparateur de date.We recommend that you set the date separator in the year month pattern to an exact string instead of using the date separator placeholder. Par exemple, pour obtenir le modèle MM-AAAA, définissez le modèle année mois sur « MM-AAAA ».For example, to get the pattern MM-yyyy, set the year month pattern to "MM-yyyy".