DateTimeFormatInfo.LongDatePattern 属性

定义

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

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

属性值

长日期值的自定义格式字符串。

例外

该属性设置为 null

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

示例

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

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:

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:

 CULTURE    PROPERTY VALUE
  en-US     dddd, MMMM d, yyyy
  ja-JP     yyyy'年'M'月'd'日'
  fr-FR     dddd d 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.LongDatePattern)

   End Sub

End Class

'This code produces the following output:
'
' CULTURE    PROPERTY VALUE
'  en-US     dddd, MMMM d, yyyy
'  ja-JP     yyyy'年'M'月'd'日'
'  fr-FR     dddd d MMMM yyyy
'

注解

属性 LongDatePattern 定义通过调用 DateTime.ToStringDateTimeOffset.ToString 方法以及提供“D”标准格式字符串的复合格式字符串返回的日期字符串的区域性特定格式。 以下示例演示了以下各项之间的关系:“D”标准格式字符串、属性 LongDatePattern 返回的自定义格式字符串以及日期的区域性特定表示形式。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2011, 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

有关可以组合以构造自定义 格式字符串 (例如“dddd, dd MMMM yyyy”)等自定义格式说明符,请参阅自定义日期和时间格式字符串。

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

如果区域性使用的日历发生更改,则此属性的值可能会更改。 例如,以下示例演示当区域性使用的对象CultureInfo更改时Calendar,表示阿拉伯语 (叙利亚) 区域性的 对象的 属性如何LongDatePattern更改。

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 MMMM, yyyy         08 رمضان, 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 MMMM, yyyy         08 رمضان, 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

适用于

另请参阅