Mega Code Archive

 
Categories / C# / Date Time
 

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) */