starcorn
starcorn

Reputation: 8551

CultureInfo nb-NO DateTime.TryParse difference in VS2019 and on dotnetfiddle.net

On my machine when I run and output the following

string locale = "nb-NO";

CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);

string shortDateFormatString = culture.DateTimeFormat.ShortDatePattern;
string shortTimeFormatString = culture.DateTimeFormat.ShortTimePattern;

I got the following output

shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH:mm"

But on dotnetfiddle.net I got the following

shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH.mm"

I suppose C# uses CLDR, so according to https://github.com/unicode-cldr/cldr-dates-full/blob/1af902b749bef761f07281f80241250053b4313d/main/nb/ca-gregorian.json#L323

Both short time pattern should be valid. And on dotnetfiddle it is possible to parse nb-NO datetime looking as following

06.12.2017 12:34
06.12.2017 12.34

However in VS2019 on my machine it is only possible to parse

06.12.2017 12:34

How is it possible it is different? both is using .NET 4.7.2.

You can check my fiddle here https://dotnetfiddle.net/68DDYz

Upvotes: 0

Views: 695

Answers (2)

Soner Gönül
Soner Gönül

Reputation: 98780

Jon is quite right (duh!)

Culture settings are tricky. Since they are stored on the windows registry, they can be different/change over .net framework versions, operating system versions, windows updates, hotfixes etc. That means even if both server uses same .NET Framework version, that doesn't mean that every culture settings will be same for both.

I can show you the it-IT culture for example.

See: .NET (3.5) formats times using dots instead of colons as TimeSeparator for it-IT culture?

For .NET Framework 3.5, it-IT culture has . as a TimeSeparator but with .NET Framework 4.0 version, it changed to : which is stated on Wikipedia.

This changes are not end of the world of course, but it was not pleasant either.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1501656

How is it possible it is different?

Because culture information is loaded from the operating system, and changes over time. Unless two machines are on the exact same version of Windows (same set of updates, hotfixes etc), it's entirely possible for them to have different values for things like short time patterns. (And yes, that's annoying, but it's part of life.)

Upvotes: 1

Related Questions