Search code examples
c#.netdatetimexamaringlobalization

DateTime's ToLongString method doesn't return day name


I'm currently using .NET's DateTime's ToLongDateString() method to parse a date string. For some cultures this works fine:

US: Wednesday, May 16, 2001

But for a few other cultures the day name is omitted (examples are Dutch, Hungarian and Icelandic cultures).

NL: 16 mei 2001

The DayNames arrays of these cultures contain the proper names for every day of the week, but for some reason they aren't used in a long date string.

I tried using the DateTimeFormat.DayNames [i] + "D" formatting solution, but it didn't work here because it would lead to double day names on cultures that do already show the day name.

 US: Wednesday Wednesday, May 16, 2001
 NL: woensdag 16 mei 2001

Is there any way to make the day name appear for cultures that omit it by default?


Solution

  • Thats correct.

    .NET does what it should do, if you have a look at the regional settings of a windows pc you can change the culture and see whats displayed in the Date (long) field and you will see the following:

    for Dutch: d. MMMM YYYY

    for Hungarian: YYYY. MMMM d.

    for Icelandic: d. MMMM YYYY

    You will have to add it manually if you really like to have it for all of them, or force a certain format layout with

    DateTime.Now.ToString("dddd, dd MM YYYY");
    

    Have a look at this page to see where the regional settings are found on a windows 7 pc: http://windows.microsoft.com/en-us/windows7/change-the-country-or-region-setting