How to get DayNames from the language only in .NET.

Suppose I have a country code (en, de, fr) and I need to display weekdays in this language. I know about RegionInfo and CultureInfo, but I can not find a solution. If I create country information from (for example) "en", I don't have DateTime data. It would also be easy to take the first relevant region. For example, en-US for en or de-DE for de.

I do not know if there are differences in DayNames, but I know that there are several months. de-DE Februar - de-AT Feber - anyway, I don't care. The event, if it can be β€œa little different” (to see Fevroir instead of Feber), is still German.

And this is what I want to achieve - write on Monday - get de and write Montag ...

Is there a way to create a region only from a language code?

+5
source share
7 answers

This part may be useful: go from "en" to CultureInfo, a faster way

CultureInfo ci = CultureInfo.CreateSpecificCulture("en")

For the second part, I believe that you are asking for the names of the days, so you write

string[] names = ci.DateTimeFormat.DayNames 
+6
source

Usually, when you say "I don't care", you start to struggle with the API.

In any case, 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);
+4
source

:

    Dim ci As CultureInfo
    For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
        Console.WriteLine(ci.Name)
    Next

: -SA BG-BG -ES ZH-TW CS-CZ -DK -DE -GR - -FI -IL Hu-HU IS-IS -IT JA-JP -KR -NL NB-NO -PL PT-BR -RO -RU -HR -SK -AL -SE -TH TR-TR -PK -UA -BY -SI ET-.. LV-LV LT-LT VI-VN -AM -Latn-AZ -ES - -ZA -GE FO-FO -IN -MY -KZ -KG SW-KE UZ-Latn-UZ -RU -IN -IN -IN -IN KN-IN MR-IN -IN -MN GL-ES -IN Syr-SY DV-MV -IQ ZH-CN -CH - -MX FR-BE NL-BE NN- PT-PT -Latn-CS -FI -Cyrl-AZ -BN UZ-Cyrl-UZ -EG ZH-HK -AT -AU ES-ES FR-CA -Cyrl-CS -LY ZH-SG -LU -CA -GT FR- - ZH-MO -NZ ES-CR FR-LU -MA -IE -PA FR-MC -TN -ZA -DO -OM -JM -VE -YE -029 ES-CO -SY -BZ ES- -JO -TT ES-AR -LB -ZW -EC -KW -PH -CL -AE -UY -BH -PY -QA -BO -SV -HN -NI -PR - -BD -Cyrl-.. TG-Cyrl-TJ -SG -MY --CN PRS-AF -SN RW-RW, -GT -RU GSW-FR -FR RM- -NZ UG-CN -FR MoH-CA ARN-CL -IE II-CN -SE -Latn-BA QUZ- IG-NG KL-GL -LU -RU -ZA QUZ-BO -NG -FI -Latn-NG -.. -PH -AF FY-NL -NP -ET IU--CA QUZ-EC - SMJ-SE -LA KH CY-RU -CN SE-SE SMJ- -IN -FI -IN -Cyrl-BA -IN -IN DSB-DE -TM SMN-FI -FR -US SE- -MT -Latn-.. -ZA XH-ZA -ZA -Latn- -Latn-CA HSB-

+1

DateTime.Today.ToString("dddd", new CultureInfo("zh-TW"))

ζ˜ŸζœŸδΈ€ ( Chinise).

+1

String()       Dim months As String()       Dim cul As New System.Globalization.CultureInfo( "de-DE" )       months = cul.DateTimeFormat.MonthNames   days = cul.DateTimeFormat.DayNames

0

: -

string culture = " "

CultureInfo myCulture = new CultureInfo ();

DateTimeFormatInfo dtfi = myCulture.DateTimeFormat;

dayString = dtfi.GetDayName( ..);

Charlie G

0

Since "de" is a neutral culture, you cannot get DayNames from DateTimeFormat if you try CultureInfo.GetCultureInfo ("de").

I would suggest that you run CultureInfo.CreateSpecificCulture ("de") in this case, since it will create a non-neutral culture ... in the case of "de" I got the culture "de-DE", back from the .NET gods: D

    CultureInfo tmp = CultureInfo.CreateSpecificCulture("de");

    string[] names = tmp.DateTimeFormat.DayNames;
    foreach(string name in names)
    {
        Console.WriteLine(name);
    }
0
source

All Articles