Answer taking into account this happens on MacOS
After digging around the source code a bit it seems that on Linux/MacOS .NET Core will use ICU for date and time formatting and in your case this results in a two digit year. There is an issue resolved by a pull request to make the year formatting consistent across platforms. However, as far as I can see this change is only scheduled to be included in .NET Core 3.
Wrong answer assuming the OS is Windows
Executing the following code
var sample = new DateTime(2050, 1, 1);
var datestr = sample.ToString("d", CultureInfo.GetCultureInfo("de"));
Console.WriteLine(datestr);
prints
01.01.2050
so it seems that the problem is specific to you.
However, while you have specified that your culture is "de_DE" your code doesn't use a culture. When no culture is specified in the ToString
call then CultureInfo.CurrentCulture
is used so I assume that you have configured Windows to use German regional format.
Windows allows you to customize the regional format and if you do that .NET will use your modified format when CultureInfo.CurrentCulture
is used. You can inspect and modify the format in the Windows Settings app:
- Settings (Windows key + I)
- Time & Language
- Region
- Change data formats
You might find this surprising and there is an even more surprising fact about the culture returned by CultureInfo.CreateSpecificCulture
that you can read about in my answer to the question When to use CultureInfo.GetCultureInfo(String) or CultureInfo.CreateSpecificCulture(String).
To avoid this feature (or quirk) of CultureInfo.CurrentCulture
you can explicitly specify a CultureInfo
when you format the date. However, if this date is displayed to the user then it's probably better to just use CultureInfo.CurrentCulture
to allow the user to freely customize the format.