I want to convert the datetime to Swedish Culture.
DateTime.Today.ToString("dd MMMM yyyy");
Above line of code gives me results as 27 December 2013
I want to have results which display december in swedish language.
The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.
The CultureInfo. CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo. CurrentCulture property, as the following example illustrates. C# Copy.
The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region. You specify the invariant culture by name by using an empty string ("") in the call to a CultureInfo instantiation method.
And if you don't want to use the culture parameter everywhere you use this method, then you can set your applications default language to swedish by doing one or few of these:
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("sv-SE");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("sv-SE");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("sv-SE");
Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
Then anywhere you call your ToString()
method it will stringify according to the current culture info that you set.
You should use Swedish Culture for that:
DateTime.Today.ToString("dd MMMM yyyy", CultureInfo.GetCultureInfo("sv-SE"));
If Swedish should be used in each ToString()
you can set up CurrentCulture:
// Or/And CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("sv-SE");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("sv-SE");
...
// Since Current Culture is Swedish, there's no need to put it explicitly
DateTime.Now.ToString("dd MMMM yyyy");
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