DateTimeFormatInfo Class : DateTimeFormatInfo « Date Time « C# / C Sharp






DateTimeFormatInfo Class

  

using System;
using System.Globalization;


public class SamplesDTFI  {

   public static void Main()  {
      DateTimeFormatInfo myDTFI = new CultureInfo( "en-US", false ).DateTimeFormat;
      DateTime myDT = new DateTime( 2010, 1, 3 );
      Console.WriteLine( "  d     {0}", myDT.ToString("d") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortDatePattern, "(ShortDatePattern)" );
      Console.WriteLine( "  D     {0}", myDT.ToString("D") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongDatePattern, "(LongDatePattern)" );
      Console.WriteLine( "  f     {0}\n", myDT.ToString("f") );
      Console.WriteLine( "  F     {0}", myDT.ToString("F") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.FullDateTimePattern, "(FullDateTimePattern)" );
      Console.WriteLine( "  g     {0}\n", myDT.ToString("g") );
      Console.WriteLine( "  G     {0}\n", myDT.ToString("G") );
      Console.WriteLine( "  m     {0}", myDT.ToString("m") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  M     {0}", myDT.ToString("M") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  r     {0}", myDT.ToString("r") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  R     {0}", myDT.ToString("R") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  s     {0}", myDT.ToString("s") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" );
      Console.WriteLine( "  t     {0}", myDT.ToString("t") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortTimePattern, "(ShortTimePattern)" );
      Console.WriteLine( "  T     {0}", myDT.ToString("T") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongTimePattern, "(LongTimePattern)" );
      Console.WriteLine( "  u     {0}", myDT.ToString("u") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" );
      Console.WriteLine( "  U     {0}\n", myDT.ToString("U") );
      Console.WriteLine( "  y     {0}", myDT.ToString("y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );
      Console.WriteLine( "  Y     {0}", myDT.ToString("Y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );

   }

}
/*
  d     1/3/2010
        M/d/yyyy (ShortDatePattern)

  D     Sunday, January 03, 2010
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Sunday, January 03, 2010 12:00 AM

  F     Sunday, January 03, 2010 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2010 12:00 AM

  G     1/3/2010 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Sun, 03 Jan 2010 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Sun, 03 Jan 2010 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2010-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2010-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Sunday, January 03, 2010 8:00:00 AM

  y     January, 2010
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2010
        MMMM, yyyy (YearMonthPattern)


*/

   
    
  








Related examples in the same category

1.CultureInfo Provides information about a specific culture
2.Determines the specific cultures that use the Chinese language, and displays the parent culture
3.Gets or sets a DateTimeFormatInfo that defines the culturally appropriate format of displaying dates and times.
4.Gets the list of calendars that can be used by the culture.
5.Custom Date and Time Format Strings
6.DateTimeFormatInfo.AbbreviatedMonthGenitiveNames
7.DateTimeFormatInfo.FullDateTimePattern
8.ALL the patterns
9.DateTimeFormatInfo.LongDatePattern
10.DateTimeFormatInfo.LongTimePattern
11.DateTimeFormatInfo.MonthDayPattern
12.DateTimeFormatInfo.RFC1123Pattern
13.DateTimeFormatInfo.ShortDatePattern
14.DateTimeFormatInfo.ShortTimePattern
15.DateTimeFormatInfo.SortableDateTimePattern
16.DateTimeFormatInfo.UniversalSortableDateTimePattern
17.DateTimeFormatInfo.YearMonthPattern
18.To Short Date Time
19.To Date Time from dmtf date