Convert DateTime to all the string supported by the specified standard date and time format specifier and culture in CSharp

Description

The following code shows how to convert DateTime to all the string supported by the specified standard date and time format specifier and culture.

Example


/*from   w ww.  j  ava 2 s. c  om*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
        DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
    
    IFormatProvider culture = 
      new System.Globalization.CultureInfo("fr-FR", true);
    // Get the short date formats using the "fr-FR" culture.
    string [] frenchJuly28Formats = 
          july28.GetDateTimeFormats('d', culture);

    // Display july28 in short date formats using "fr-FR" culture.
    foreach (string format in frenchJuly28Formats) {
      System.Console.WriteLine(format);
    }

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var