Last active
January 2, 2016 03:29
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is setup to run in LinqPad