0

Where do I put the new CultureInfo("nl-NL")? The user needs to give a date. The programe needs to show the day in Dutch.

DateTime date;

System.Console.Write("give date (DD/MM/JJJJ) : ");
date = DateTime.Parse(Console.ReadLine());

System.Console.Write("the day is a  " + date.DayOfWeek);
Kartercas
  • 15
  • 1
  • 6
  • Possible duplicate of [DateTime.Now.DayOfWeek.ToString() with CultureInfo](http://stackoverflow.com/questions/5716762/datetime-now-dayofweek-tostring-with-cultureinfo) – Eugene Podskal Jan 21 '17 at 13:05
  • @EugenePodskal I have seen it, and its different. – Kartercas Jan 21 '17 at 13:10
  • 1
    In such a case you should be more specific about what does `Where do I put the new CultureInfo("nl-NL")?` mean. Your question should at least describe the result you strive to achieve. Otherwise we are just left with trying to guess what you actually want, and that doesn't usually end well. See http://stackoverflow.com/help/how-to-ask – Eugene Podskal Jan 21 '17 at 13:15
  • @EugenePodskal Is this better? – Kartercas Jan 21 '17 at 13:26
  • Yes, it is better. And, using the answer from proposed duplicate, I get `zaterdag` as a result. So I am not sure how this question is different from that one. – Eugene Podskal Jan 21 '17 at 13:29
  • Becouse the user need to give a date in console and not use Today. – Kartercas Jan 21 '17 at 13:38
  • Ehhm, and what prevents you from substituting `DateTime.Now` with the parsed `date` variable? – Eugene Podskal Jan 21 '17 at 14:07

3 Answers3

1

You can use it directly. CultureInfo implements the IFormatProvider interface.

DateTime date;

var cultureInfo = new CultureInfo("nl-NL");

System.Console.Write("give date (DD/MM/JJJJ) : ");
date = DateTime.Parse(Console.ReadLine(),cultureInfo);



System.Console.Write("the day is a  " + cultureInfo.DateTimeFormat.GetDayName(date.DayOfWeek));
Ivaylo Stoev
  • 457
  • 3
  • 7
1
var newCulture = new System.Globalization.CultureInfo("nl-NL");
var dayOfWeek = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);

System.Console.WriteLine("the day is a " + dayOfWeek);
Alf Moh
  • 7,159
  • 5
  • 41
  • 50
0

Put this with the other using statements:

using System.Threading;
using System.Globalization;

Put this as the first line of code in your Main method:

Thread.CurrentThread.CurrentCulture = 
        new CultureInfo("nl-NL");
Console.WriteLine("Weekday: {0}", Thread.CurrentThread.CurrentCulture.DateTimeFormat
   .GetDayName(DateTime.Today.DayOfWeek));

Then your application will use that culture. It will be used for datetime formatting, number formatting etc.

If you were using a UI application, like windows forms, you would also need to set the ui culture like this:

Thread.CurrentThread.CurrentUICulture = 
     new CultureInfo("nl-NL");

When you set the CurrentUICulture then the application will get information from your resources file for displaying labels etc in the UI.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64