Export (0) Print
Expand All

DateTimeFormatInfo.GetAllDateTimePatterns Method (Char)

Returns all the standard patterns in which DateTime values can be formatted using the specified format character.

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

public string[] GetAllDateTimePatterns (
	char format
)
public String[] GetAllDateTimePatterns (
	char format
)
public function GetAllDateTimePatterns (
	format : char
) : String[]

Parameters

format

A standard format character.

Return Value

An array containing the standard patterns in which DateTime values can be formatted using the specified format character.

Exception typeCondition

ArgumentException

format is not a valid standard format character.

See the summary page of the DateTimeFormatInfo class for a list of the standard format characters and their associated patterns.

The following code example gets and prints the DateTime patterns for the current calendar.

 using System;
 using System.Globalization;
 public class SamplesDateTimeFormatInfo  {
 
    public static void Main()  {
 
       // Creates a new DateTimeFormatinfo.
       DateTimeFormatInfo myDtfi = new DateTimeFormatInfo();
 
       // Gets and prints all the patterns.
       String[] myPatternsArray = myDtfi.GetAllDateTimePatterns();
       Console.WriteLine( "ALL the patterns:" );
       PrintIndexAndValues( myPatternsArray );
 
       // Gets and prints the pattern(s) associated with some of the format characters.
       myPatternsArray = myDtfi.GetAllDateTimePatterns('d');
       Console.WriteLine( "The patterns for 'd':" );
       PrintIndexAndValues( myPatternsArray );
 
       myPatternsArray = myDtfi.GetAllDateTimePatterns('D');
       Console.WriteLine( "The patterns for 'D':" );
       PrintIndexAndValues( myPatternsArray );
 
       myPatternsArray = myDtfi.GetAllDateTimePatterns('f');
       Console.WriteLine( "The patterns for 'f':" );
       PrintIndexAndValues( myPatternsArray );
 
       myPatternsArray = myDtfi.GetAllDateTimePatterns('F');
       Console.WriteLine( "The patterns for 'F':" );
       PrintIndexAndValues( myPatternsArray );
 
       myPatternsArray = myDtfi.GetAllDateTimePatterns('r');
       Console.WriteLine( "The patterns for 'r':" );
       PrintIndexAndValues( myPatternsArray );
 
       myPatternsArray = myDtfi.GetAllDateTimePatterns('R');
       Console.WriteLine( "The patterns for 'R':" );
       PrintIndexAndValues( myPatternsArray );
    }
 
    public static void PrintIndexAndValues( String[] myArray )  {
       int i = 0;
       foreach ( String s in myArray )
          Console.WriteLine( "\t[{0}]:\t{1}", i++, s );
       Console.WriteLine();
    }
 }


/* 
This code produces the following output.

ALL the patterns:
        [0]:    MM/dd/yyyy
        [1]:    dddd, dd MMMM yyyy
        [2]:    dddd, dd MMMM yyyy HH:mm
        [3]:    dddd, dd MMMM yyyy hh:mm tt
        [4]:    dddd, dd MMMM yyyy H:mm
        [5]:    dddd, dd MMMM yyyy h:mm tt
        [6]:    dddd, dd MMMM yyyy HH:mm:ss
        [7]:    MM/dd/yyyy HH:mm
        [8]:    MM/dd/yyyy hh:mm tt
        [9]:    MM/dd/yyyy H:mm
        [10]:   MM/dd/yyyy h:mm tt
        [11]:   MM/dd/yyyy HH:mm:ss
        [12]:   MMMM dd
        [13]:   MMMM dd
        [14]:   ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        [15]:   ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        [16]:   yyyy'-'MM'-'dd'T'HH':'mm':'ss
        [17]:   HH:mm
        [18]:   hh:mm tt
        [19]:   H:mm
        [20]:   h:mm tt
        [21]:   HH:mm:ss
        [22]:   yyyy'-'MM'-'dd HH':'mm':'ss'Z'
        [23]:   dddd, dd MMMM yyyy HH:mm:ss
        [24]:   yyyy MMMM
        [25]:   yyyy MMMM

The patterns for 'd':
        [0]:    MM/dd/yyyy

The patterns for 'D':
        [0]:    dddd, dd MMMM yyyy

The patterns for 'f':
        [0]:    dddd, dd MMMM yyyy HH:mm
        [1]:    dddd, dd MMMM yyyy hh:mm tt
        [2]:    dddd, dd MMMM yyyy H:mm
        [3]:    dddd, dd MMMM yyyy h:mm tt

The patterns for 'F':
        [0]:    dddd, dd MMMM yyyy HH:mm:ss

The patterns for 'r':
        [0]:    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'

The patterns for 'R':
        [0]:    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
*/


import System.*;
import System.Globalization.*;

public class SamplesDateTimeFormatInfo
{
    public static void main(String[] args)
    {
        // Creates a new DateTimeFormatinfo.
        DateTimeFormatInfo myDtfi = new DateTimeFormatInfo();
        // Gets and prints all the patterns.
        String myPatternsArray[] = myDtfi.GetAllDateTimePatterns();
        Console.WriteLine("ALL the patterns:");
        PrintIndexAndValues(myPatternsArray);
        // Gets and prints the pattern(s) associated with some of the format
        // characters.
        myPatternsArray = myDtfi.GetAllDateTimePatterns('d');
        Console.WriteLine("The patterns for 'd':");
        PrintIndexAndValues(myPatternsArray);

        myPatternsArray = myDtfi.GetAllDateTimePatterns('D');
        Console.WriteLine("The patterns for 'D':");
        PrintIndexAndValues(myPatternsArray);

        myPatternsArray = myDtfi.GetAllDateTimePatterns('f');
        Console.WriteLine("The patterns for 'f':");
        PrintIndexAndValues(myPatternsArray);

        myPatternsArray = myDtfi.GetAllDateTimePatterns('F');
        Console.WriteLine("The patterns for 'F':");
        PrintIndexAndValues(myPatternsArray);

        myPatternsArray = myDtfi.GetAllDateTimePatterns('r');
        Console.WriteLine("The patterns for 'r':");
        PrintIndexAndValues(myPatternsArray);

        myPatternsArray = myDtfi.GetAllDateTimePatterns('R');
        Console.WriteLine("The patterns for 'R':");
        PrintIndexAndValues(myPatternsArray);
    } //main

    public static void PrintIndexAndValues(String[] myArray)
    {
        int i = 0;      
        String s = null;
        for (int iCtr = 0; iCtr < myArray.get_Length(); iCtr++) {
            s = myArray[iCtr];
            Console.WriteLine("\t[{0}]:\t{1}", (Int32)i++, s);
        }
        Console.WriteLine();
    } //PrintIndexAndValues
} //SamplesDateTimeFormatInfo

/* 
This code produces the following output.

ALL the patterns:
        [0]:    MM/dd/yyyy
        [1]:    dddd, dd MMMM yyyy
        [2]:    dddd, dd MMMM yyyy HH:mm
        [3]:    dddd, dd MMMM yyyy hh:mm tt
        [4]:    dddd, dd MMMM yyyy H:mm
        [5]:    dddd, dd MMMM yyyy h:mm tt
        [6]:    dddd, dd MMMM yyyy HH:mm:ss
        [7]:    MM/dd/yyyy HH:mm
        [8]:    MM/dd/yyyy hh:mm tt
        [9]:    MM/dd/yyyy H:mm
        [10]:   MM/dd/yyyy h:mm tt
        [11]:   MM/dd/yyyy HH:mm:ss
        [12]:   MMMM dd
        [13]:   MMMM dd
        [14]:   ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        [15]:   ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        [16]:   yyyy'-'MM'-'dd'T'HH':'mm':'ss
        [17]:   HH:mm
        [18]:   hh:mm tt
        [19]:   H:mm
        [20]:   h:mm tt
        [21]:   HH:mm:ss
        [22]:   yyyy'-'MM'-'dd HH':'mm':'ss'Z'
        [23]:   dddd, dd MMMM yyyy HH:mm:ss
        [24]:   yyyy MMMM
        [25]:   yyyy MMMM

The patterns for 'd':
        [0]:    MM/dd/yyyy

The patterns for 'D':
        [0]:    dddd, dd MMMM yyyy

The patterns for 'f':
        [0]:    dddd, dd MMMM yyyy HH:mm
        [1]:    dddd, dd MMMM yyyy hh:mm tt
        [2]:    dddd, dd MMMM yyyy H:mm
        [3]:    dddd, dd MMMM yyyy h:mm tt

The patterns for 'F':
        [0]:    dddd, dd MMMM yyyy HH:mm:ss

The patterns for 'r':
        [0]:    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'

The patterns for 'R':
        [0]:    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
*/


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft