DateTimeFormatInfo.LongDatePattern Property
Gets or sets the custom format string, which is associated with the "D" standard format string for a long date value.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| ArgumentNullException | The property is being set to Nothing. |
| InvalidOperationException | The property is being set and the DateTimeFormatInfo object is read-only. |
The LongDatePattern property defines the culture-specific format of dates 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. 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.
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 dd, 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
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".
You should set the date separator in the long date pattern to an exact string instead of using the date separator placeholder. For example, to obtain the pattern MM-DD-yyyy, set the long date pattern to "MM-DD-yyyy".
The value of this property may change if the calendar used by a culture changes. For instance, the following example shows how theLongDatePattern property of a CultureInfo object that represents the Arabic (Syria) culture changes when the Calendar object used by the culture changes.
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
The following example displays the value of the LongDatePattern property for a few cultures.
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 dd, yyyy ' ja-JP yyyy'?'M'?'d'?' ' fr-FR dddd d MMMM yyyy '
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.