DateTimeFormatInfo.GetAllDateTimePatterns Method (Char)

 

Returns all the patterns in which date and time values can be formatted using the specified standard format string.

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

member GetAllDateTimePatterns : 
        format:char -> string[]

Parameters

format
Type: System.Char

A standard format string.

Return Value

Type: System.String[]

An array containing the standard patterns in which date and time values can be formatted using the specified format string.

Exception Condition
ArgumentException

format is not a valid standard format string.

This method returns an array containing the custom format strings that correspond to a particular standard format string. See Standard Date and Time Format Strings for a list of the standard format strings.

You can use the custom format strings in the array returned by the GetAllDateTimePatterns method in formatting operations. However, if you do, the string representation of a date and time value returned in that formatting operation cannot always be parsed successfully by the Parse and TryParse methods. Therefore, you cannot assume that the custom format strings returned by the GetAllDateTimePatterns method can be used to round-trip date and time values. The following example illustrates this problem. It retrieves a DateTimeFormatInfo object that contains formatting information for the Russia (Russian) culture. It calls the GetAllDateTimePatterns(Char) method for each standard format string, and then passes each custom format string in the returned array to the DateTime.ToString(String) method to create the string representation of a date and time. This example then attempts to parse this value by calling the DateTime.TryParse(String, DateTime) method. As the output from the example shows, some of the custom format strings do not produce a date and time value that successfully round-trips.

No code example is currently available or this language may not be supported.

To parse the string representation of a date and time that can be expressed in a number of predefined custom formats, call one of the following methods:

The custom format strings in the array returned by the GetAllDateTimePatterns method depends on the current calendar of the culture for which the DateTimeFormatInfo object supplies formatting information. If the calendar changes, the array returned by this method also changes.

The following example displays the date and time patterns for the current calendar.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: