Export (0) Print
Expand All

DateTime.GetDateTimeFormats Method (Char)

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

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

public string[] GetDateTimeFormats(
	char format
)

Parameters

format
Type: System.Char

A standard date and time format string (see Remarks).

Return Value

Type: System.String[]
A string array where each element is the representation of the value of this instance formatted with the format standard date and time format specifier.

ExceptionCondition
FormatException

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 information from the current culture. For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.

Important noteImportant

Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data. The data returned by this method can change if the current culture changes, the user overrides individual cultural settings, or an update occurs to the system's cultural data.

The following example demonstrates the GetDateTimeFormats(Char) method. It displays the string representation of a date using the long date format specifier ("D") for the current culture.

		DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
		
		// Get the long date formats using the current culture. 
		string [] longJuly28Formats = 
					july28.GetDateTimeFormats('D');

		// Display july28 in all long date formats. 
		foreach (string format in longJuly28Formats) {
			Console.WriteLine(format);
		}
      // The example displays the following output: 
      //       Tuesday, July 28, 2009 
      //       July 28, 2009 
      //       Tuesday, 28 July, 2009 
      //       28 July, 2009

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft