Skip to content

Instantly share code, notes, and snippets.

@jerry4
Last active January 2, 2016 03:29
Show Gist options
  • Save jerry4/8243875 to your computer and use it in GitHub Desktop.
Save jerry4/8243875 to your computer and use it in GitHub Desktop.
What cultures use 24 hour time? (example limits to english cultures) from stack overflow answer...
void Main()
{
var cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures);
foreach(var cultureInfo in cultures)
{
Thread.CurrentThread.CurrentCulture = cultureInfo;
var datetime = new DateTime(2000, 1, 1, 23, 0, 0);
var formatted = datetime.ToString("t");
var is24Hrs = formatted.Contains("23");
//Assert.AreEqual(is24Hrs, cultureInfo.Is24Hrs());
if (cultureInfo.TwoLetterISOLanguageName == "en")
(cultureInfo.NativeName + " " + is24Hrs.ToString() + " " + cultureInfo.Is24Hrs()).Dump();
}
}
// Define other methods and classes here
public static class DateTimeExtensions
{
public static bool Is24Hrs(this System.Globalization.CultureInfo cultureInfo)
{
return cultureInfo.DateTimeFormat.ShortTimePattern.Contains("H");
}
}
@jerry4
Copy link
Author

jerry4 commented Jan 3, 2014

This is setup to run in LinqPad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment