Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DateTime.GetDateTimeFormats Method (Char, IFormatProvider)

Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier and culture-specific formatting information.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Public Function GetDateTimeFormats ( _
	format As Char, _
	provider As IFormatProvider _
) As String()


Type: System.Char

A date and time format string (see Remarks).

Type: System.IFormatProvider

An object that supplies culture-specific formatting information about this instance.

Return Value

Type: System.String()
A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.


format is not a valid standard date and time format specifier character.

The format parameter can be any of the standard date and time format specifiers. These include d, D, f, F, g, G, M (or m), O (or o), R (or r), s, t, T, u, U, and Y (or y). For more information, see Standard Date and Time Format Strings.

Each element of the return value is formatted using culture-specific information supplied by provider.

Important noteImportant

Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data unless provider is a CultureInfo object that represents the invariant culture. The data returned by this method can change if the user overrides the individual cultural settings of provider or if an update occurs to the system's cultural data for provider.

The following example demonstrates the GetDateTimeFormats(Char, IFormatProvider) method. It displays the string representations of a date using the short date format specifier ("d") for the fr-FR culture.

		Dim july28 As Date = #7/28/2009 5:23:15#
		Dim culture As IFormatProvider = New System.Globalization.CultureInfo("fr-FR", True)
		' Get the short date formats using the "fr-FR" culture. 
		Dim frenchJuly28Formats() As String = july28.GetDateTimeFormats("d"c, culture)

		' Display july28 in short date formats using "fr-FR" culture. 
		For Each format As String In frenchJuly28Formats
      ' The example displays the following output: 
      '       28/07/2009 
      '       28/07/09 
      '       28.07.09 
      '       28-07-09 
      '       2009-07-28

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft