DateTimeFormatInfo.LongDatePattern DateTimeFormatInfo.LongDatePattern DateTimeFormatInfo.LongDatePattern DateTimeFormatInfo.LongDatePattern Property

Definizione

Ottiene o imposta la stringa di formato personalizzata per un valore di data estesa.Gets or sets the custom format string for a long date value.

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

Valore della proprietà

La stringa di formato personalizzata per un valore di data estesa.The custom format string for a long date value.

Eccezioni

La proprietà viene impostata su null.The property is being set to null.

La proprietà viene impostata e l'oggetto DateTimeFormatInfo è di sola lettura.The property is being set and the DateTimeFormatInfo object is read-only.

Esempi

Nell'esempio seguente visualizza il valore della LongDatePattern proprietà per alcune lingue.The following example displays the value of the LongDatePattern property 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->LongDatePattern );
}

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     dddd, MMMM dd, yyyy
ja-JP     yyyy'?'M'?'d'?'
fr-FR     dddd d 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.LongDatePattern );

   }

}

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

 CULTURE    PROPERTY VALUE
  en-US     dddd, MMMM d, yyyy
  ja-JP     yyyy'?'M'?'d'?'
  fr-FR     dddd d MMMM yyyy

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

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

Commenti

Il LongDatePattern proprietà definisce il formato specifico delle impostazioni cultura delle stringhe di data che vengono restituiti dalle chiamate per il DateTime.ToString e DateTimeOffset.ToString metodi e dal formato composito stringhe che vengono forniti la stringa di formato standard "D".The LongDatePattern 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 "D" standard format string. Nell'esempio seguente illustra le relazioni tra i valori seguenti: la stringa di formato standard "D", il formato personalizzato restituito dalla stringa di LongDatePattern proprietà e la rappresentazione di impostazioni cultura specifiche di una data.The following example illustrates the relationships among the following: the "D" standard format string, the custom format string returned by the LongDatePattern property, and the culture-specific representation of a date.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2001, 11, 12);
      string[] cultureNames = { "en-US", "fr-FR", "ru-RU", "de-DE" };
      Console.WriteLine("{0,-7} {1,-20} {2:D}\n", "Culture", "Long Date Pattern", "Date");
      foreach (var cultureName in cultureNames) {
         CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName);
         Console.WriteLine("{0,-7} {1,-20} {2}", 
                           culture.Name, 
                           culture.DateTimeFormat.LongDatePattern, 
                           date1.ToString("D", culture));                 
      }
   }
}
// The example displays the following output:
//    Culture Long Date Pattern    Date
//    en-US   dddd, MMMM d, yyyy  Saturday, November 12, 2011
//    fr-FR   dddd d MMMM yyyy     samedi 12 novembre 2011
//    ru-RU   d MMMM yyyy 'г.'     12 ноября 2011 г.
//    de-DE   dddd, d. MMMM yyyy   Samstag, 12. November 2011
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim date1 As Date = #11/12/2011#
      Dim cultureNames() As String = { "en-US", "fr-FR", "ru-RU", "de-DE" }
      Console.WriteLine("{0,-7} {1,-20} {2:D}", "Culture", "Long Date Pattern", "Date")
      Console.WriteLine()
      For Each cultureName In cultureNames
         Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture(cultureName)
         Console.WriteLine("{0,-7} {1,-20} {2}", culture.Name, culture.DateTimeFormat.LongDatePattern, 
                           date1.ToString("D", culture))                 
      Next
   End Sub
End Module
' The example displays the following output:
'    Culture Long Date Pattern    Date
'    en-US   dddd, MMMM d, yyyy  Saturday, November 12, 2011
'    fr-FR   dddd d MMMM yyyy     samedi 12 novembre 2011
'    ru-RU   d MMMM yyyy 'г.'     12 ноября 2011 г.
'    de-DE   dddd, d. MMMM yyyy   Samstag, 12. November 2011

Visualizzare Custom Date and Time Format Strings per gli identificatori di formato personalizzato singoli che possono essere combinati per costruire stringhe di formato personalizzato, ad esempio "dddd, dd MMMM yyyy".See Custom Date and Time Format Strings for individual custom format specifiers that can be combined to construct custom format strings such as "dddd, dd MMMM yyyy".

È consigliabile impostare il separatore della data nel modello di data estesa in una stringa esatta anziché utilizzare il segnaposto separatore della data.You should set the date separator in the long date pattern to an exact string instead of using the date separator placeholder. Ad esempio, per ottenere il modello MM-GG-AAAA, impostare il modello di data estesa per "MM-gg-aaaa".For example, to obtain the pattern MM-DD-yyyy, set the long date pattern to "MM-DD-yyyy".

Il valore di questa proprietà può variare se il calendario usato da delle modifiche delle impostazioni cultura.The value of this property may change if the calendar used by a culture changes. Ad esempio, l'esempio seguente illustra come la LongDatePattern proprietà di un CultureInfo le modifiche dell'oggetto che rappresenta le impostazioni cultura arabo (Siria) quando il Calendar oggetto utilizzato per le modifiche delle impostazioni cultura.For instance, the following example shows how the LongDatePattern property of a CultureInfo object that represents the Arabic (Syria) culture changes when the Calendar object used by the culture changes.

using System;
using System.Globalization;
using System.IO;

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2011, 8, 7);
      CultureInfo ci = CultureInfo.CreateSpecificCulture("ar-SY");
      StreamWriter sw = new StreamWriter(@".\arSYCalendars.txt"); 

      sw.WriteLine("{0,-32} {1,-21} {2}\n", 
                   "Calendar", "Long Date Pattern", "Example Date");
      foreach (var cal in ci.OptionalCalendars) {
         ci.DateTimeFormat.Calendar = cal;
         sw.WriteLine("{0,-32} {1,-21} {2}", GetCalendarName(cal), 
                                             ci.DateTimeFormat.LongDatePattern,
                                             date1.ToString("D", ci));
      }     
      sw.Close();
   }

   private static string GetCalendarName(Calendar cal)
   {
      string calName;
      calName = cal.GetType().Name.Substring(0, cal.GetType().Name.IndexOf("Cal"));
      if (calName.Equals("Gregorian")) {
         GregorianCalendar grCal = cal as GregorianCalendar;
         calName += String.Format("-{0}", grCal.CalendarType);    
      }
      return calName;
   }
}
// The example generates the following output:
//    Calendar                         Long Date Pattern     Example Date
//    
//    Gregorian-Localized              dd MMMM, yyyy         07 آب, 2011
//    UmAlQura                         dd/MMMM/yyyy          07/رمضان/1432
//    Hijri                            dd/MM/yyyy            08/09/1432
//    Gregorian-USEnglish              dddd, MMMM dd, yyyy   Sunday, August 07, 2011
//    Gregorian-MiddleEastFrench       dddd, MMMM dd, yyyy   dimanche, août 07, 2011
//    Gregorian-TransliteratedEnglish  dddd, MMMM dd, yyyy   الأحد, أغسطس 07, 2011
//    Gregorian-TransliteratedFrench   dddd, MMMM dd, yyyy   الأحد, أوت 07, 2011
Imports System.Globalization
Imports System.IO

Module Example
   Public Sub Main()
      Dim date1 As Date = #8/7/2011#
      Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("ar-SY")
      Dim sw As New StreamWriter(".\arSYCalendars.txt") 

      sw.WriteLine("{0,-32} {1,-21} {2}", 
                   "Calendar", "Long Date Pattern", "Example Date")
      sw.WriteLine()
      For Each cal As Calendar In ci.OptionalCalendars
         ci.DateTimeFormat.Calendar = cal
         sw.WriteLine("{0,-32} {1,-21} {2}", GetCalendarName(cal), 
                                             ci.DateTimeFormat.LongDatePattern,
                                             date1.ToString("D", ci))
      Next     
      sw.Close()
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Dim calName As String
      calName = cal.GetType().Name.Substring(0, cal.GetType().Name.IndexOf("Cal"))
      If calName.Equals("Gregorian") Then
         Dim grCal As GregorianCalendar = DirectCast(cal, GregorianCalendar)
         calName += String.Format("-{0}", grCal.CalendarType)    
      End If
      Return calName
   End Function
End Module
' The example generates the following output:
'    Calendar                         Long Date Pattern     Example Date
'    
'    Gregorian-Localized              dd MMMM, yyyy         07 آب, 2011
'    UmAlQura                         dd/MMMM/yyyy          07/رمضان/1432
'    Hijri                            dd/MM/yyyy            08/09/1432
'    Gregorian-USEnglish              dddd, MMMM dd, yyyy   Sunday, August 07, 2011
'    Gregorian-MiddleEastFrench       dddd, MMMM dd, yyyy   dimanche, août 07, 2011
'    Gregorian-TransliteratedEnglish  dddd, MMMM dd, yyyy   الأحد, أغسطس 07, 2011
'    Gregorian-TransliteratedFrench   dddd, MMMM dd, yyyy   الأحد, أوت 07, 2011

Si applica a

Vedi anche