fork download
  1. using System;
  2. using System.Linq;
  3. using System.Globalization;
  4.  
  5. public class Test
  6. {
  7. public static CultureInfo getCultureByEnglishName(String englishName)
  8. {
  9. //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
  10. //cultures installed with the .Net Framework
  11. CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
  12. // get culture by it's english name
  13. var culture = cultures.FirstOrDefault(c => c.EnglishName.ToLower() == englishName.ToLower());
  14. return culture;
  15. }
  16.  
  17. public static void Main()
  18. {
  19. String name = "Japanese (Japan)";
  20. CultureInfo japanCulture = getCultureByEnglishName(name);
  21. Console.WriteLine("Culture: " + japanCulture.ToString());
  22. Console.WriteLine("Today: " + DateTime.Now.ToString("dddd",japanCulture));
  23. }
  24. }
Success #stdin #stdout 0.04s 34072KB
stdin
Standard input is empty
stdout
Culture: ja-JP
Today: 火曜日