Assume that I only have a country code (en, de, fr) and I need to display the weekdays in this language. I know about RegionInfo and CultureInfo - but I can't find a solution. If I create a country info from (for an example) "en" I have no DateTime info in it. It would also be OK to just take the first matching Region. For an example en-US for en or de-DE for de.
I don't know if there are differences in DayNames but I know there are some for the months. de-DE Februar - de-AT Feber -- anyhow I don't care. Event if it may be "a bit different" (to see Februar instead of Feber) - it is still German.
And that's what I want to achive - get en an write Monday - get de and write Montag...
Is there a way to create a region just from a language code?
This piece may be helpful: to go from "en" to the CultureInfo, a quicker way is
CultureInfo ci = CultureInfo.CreateSpecificCulture("en")
For the second part, I believe you are asking for day names, so you would write
string[] names = ci.DateTimeFormat.DayNames
It's usually when you say "I don't care" that you start fighting the APIs.
Anyway, this should work:
var list = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
var ci = list.FirstOrDefault(c => c.IetfLanguageTag.StartsWith("de"));
var ri = new RegionInfo(ci.Name);
Console.WriteLine("Today = {0:dddd MMMM yyyy}", DateTime.Today);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With