0

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

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
starcorn
  • 8,261
  • 23
  • 83
  • 124

2 Answers2

1

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.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • what would be the suggested resolution though, would I need to take the different cases in consideration? – starcorn Apr 25 '19 at 15:35
  • @starcorn: I don't really have enough context to suggest a solution, I'm afraid. I can explain the behaviour you're seeing, but I don't know where the data comes from, what your constraints are etc. – Jon Skeet Apr 25 '19 at 16:37
0

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.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364