Skip to content

Instantly share code, notes, and snippets.

@AuthorProxy
Created August 19, 2014 11:06
Show Gist options
  • Select an option

  • Save AuthorProxy/faaa682981e32a034958 to your computer and use it in GitHub Desktop.

Select an option

Save AuthorProxy/faaa682981e32a034958 to your computer and use it in GitHub Desktop.
Testing different formats for date and time
using System;
using System.Globalization;
using System.Threading;
namespace Program
{
public class Program
{
private static void thread_test()
{
// create date time 2009-2-15 12:05:33.125
DateTime dt = new DateTime(2009, 2, 15, 13, 5, 33, 125);
string[] dateTimeFormats = new string[] {
"{0:y yy yyy yyyy}",// "9 09 009 2009" year
"{0:M MM MMM MMMM}",// "2 02 Feb February" month
"{0:d dd ddd dddd}",// "15 15 Sun Sunday" day
"{0:h hh H HH}", // "1 01 13 13" hour 12/24
"{0:m mm}", // "5 05" minute
"{0:s ss}", // "33 33" second
"{0:f ff fff ffff}",// "1 12 125 1250" sec.fraction
"{0:F FF FFF FFFF}",// "1 12 125 125" without zeroes
"{0:z zz zzz}", // "+1 +01 +01:00" time zone
// month/day numbers with and without leading zeroes
"{0:MM/dd/yyyy}",// "02/15/2009"
"{0:M/d/yyyy}", // "2/15/2009"
// day/month names
"{0:ddd, MMM d, yyyy}", // "Sun, Feb 15, 2009"
"{0:dddd, MMMM d, yyyy}",// "Sunday, February 15, 2008"
// two/four digit year
"{0:MM/dd/yy}", // "02/15/09"
"{0:MM/dd/yyyy}",// "02/15/2009"
// standard format specifiers
"{0:t}", // "1:05 PM" ShortTime
"{0:d}", // "2/15/2009" ShortDate
"{0:T}", // "4:05:07 PM" LongTime
"{0:D}", // "Sunday, February 15, 2008" LongDate
"{0:f}", // "Sunday, February 15, 2008 4:05 PM" LongDate+ShortTime
"{0:F}", // "Sunday, February 015, 2008 4:05:07 PM" FullDateTime
"{0:g}", // "2/15/2009 1:05 PM" ShortDate+ShortTime
"{0:G}", // "2/15/2009 1:05:33 PM" ShortDate+LongTime
"{0:m}", // "February 15" MonthDay
"{0:y}", // "February, 2009" YearMonth
"{0:r}", // "Sun, 15 Feb 2009 13:05:33 GMT" RFC1123
"{0:s}", // "2009-02-15T13:05:33" SortableDateTime
"{0:u}" // "2009-02-15 13:05:33Z" UniversalSortableDateTime
};
for ( int i = 0; i < dateTimeFormats.Length; i++)
{
Console.Write( "{0}", dateTimeFormats[i]);
Console.SetCursorPosition(25, i);
Console.Write(dateTimeFormats[i], dt);
Console.WriteLine();
}
Console.WriteLine( "\nYour Current Culture is: {0}" , CultureInfo.CurrentCulture.Name);
Console.ReadLine(); //take a break...
}
public static void Main( string[] args)
{
Thread t = new Thread(thread_test);
//Force the use of a specific culture.
t.CurrentCulture = new CultureInfo("en-US" );
t.Start();
t.Join();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment