C# CultureInfo nb在VS2019和dotnetfiddle.net上没有DateTime.TryParse差异
在我的机器上运行并输出以下内容时C# CultureInfo nb在VS2019和dotnetfiddle.net上没有DateTime.TryParse差异,c#,datetime,cultureinfo,C#,Datetime,Cultureinfo,在我的机器上运行并输出以下内容时 string locale = "nb-NO"; CultureInfo culture = CultureInfo.CreateSpecificCulture(locale); string shortDateFormatString = culture.DateTimeFormat.ShortDatePattern; string shortTimeFormatString = culture.DateTimeFormat.ShortTimePatter
string locale = "nb-NO";
CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);
string shortDateFormatString = culture.DateTimeFormat.ShortDatePattern;
string shortTimeFormatString = culture.DateTimeFormat.ShortTimePattern;
shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH.mm"
06.12.2017 12:34
06.12.2017 12.34
我得到了以下输出
shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH:mm"
但在dotnetfiddle.net上,我得到了以下信息
string locale = "nb-NO";
CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);
string shortDateFormatString = culture.DateTimeFormat.ShortDatePattern;
string shortTimeFormatString = culture.DateTimeFormat.ShortTimePattern;
shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH.mm"
06.12.2017 12:34
06.12.2017 12.34
我想C#使用CLDR,所以根据
两种短时模式都应该有效。
在dotnetfiddle上,可以解析nb NO datetime,如下所示
string locale = "nb-NO";
CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);
string shortDateFormatString = culture.DateTimeFormat.ShortDatePattern;
string shortTimeFormatString = culture.DateTimeFormat.ShortTimePattern;
shortDateFormatString "dd.MM.yyyy"
ShortTimePattern "HH.mm"
06.12.2017 12:34
06.12.2017 12.34
然而,在我的机器上的VS2019中,只能解析
06.12.2017 12:34
这怎么可能不同呢?两者都使用.NET4.7.2
你可以在这里检查我的小提琴
这怎么可能不同呢
因为区域性信息是从操作系统加载的,并且随着时间的推移而变化。除非两台机器在完全相同的Windows版本上(相同的更新集、修补程序等),否则它们完全有可能在短时间模式等方面具有不同的值。(是的,这很烦人,但这是生活的一部分。)乔恩说得很对(嗯!)
文化设置很棘手。由于它们存储在windows注册表中,因此它们可以与.net framework版本、操作系统版本、windows更新、修补程序等不同/更改。这意味着即使两台服务器使用相同的.net framework版本,也不意味着两台服务器的每个区域性设置都相同
例如,我可以向您展示it
文化
见:
对于.NET Framework 3.5,it
文化将
作为一个TimeSeparator
,但对于.NET Framework 4.0版本,它更改为:
,这在维基百科上有所说明
这种变化当然不是世界末日,但也不令人愉快。不过,建议的解决方案是什么,我需要考虑不同的情况吗?@starcorn:恐怕我没有足够的背景来提出解决方案。我可以解释你看到的行为,但我不知道数据来自哪里,你的限制是什么等等。