11

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.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Manoj Sethi
  • 1,898
  • 8
  • 26
  • 56

3 Answers3

19

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");    
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
6

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.

Tolga Evcimen
  • 7,112
  • 11
  • 58
  • 91
  • 1
    You do not have to create `new` (identical) instances every time. If you do `CultureInfo.GetCultureInfo("sv-SE")` you will re-use the same (cached) instance. – Jeppe Stig Nielsen Apr 01 '19 at 08:10
1
DateTime.Today.ToString("dd MMMM yyyy", new CultureInfo("sv-SE"));

refer here

// Creates and initializes the CultureInfo which uses the international sort.

DateTime.Today.ToString("dd MMMM yyyy",new CultureInfo("sv-SE");

// Creates and initializes the CultureInfo which uses the traditional sort.

DateTime.Today.ToString("dd MMMM yyyy",new CultureInfo(0x041D);
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53