gpt4 book ai didi

c# - Linux 上的 .net 核心日期格式

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:51 27 4
gpt4 key购买 nike

我正在将我的代码从 .net 框架迁移到 .net 核心并在 Linux 机器上测试它,我遇到的问题之一是调用 DateTime ToString() 函数时的日期格式,在 Windows 中是默认格式日期格式由操作系统引导,可以在设置中自定义我试图通过定义具有所需格式的新语言环境文件并设置适当的变量(LC_Time)来在 Linux 中做类似的事情。当向系统询问日期时,我得到了所需格式的答案,但在运行代码时,我仍然得到“错误”的答案。我错过了什么吗?

最佳答案

老问题,但我刚遇到这个问题。这是一个"bug / feature / expected behavior" .NET Core 2...

This is happening because the default short date for en-US (on Linux) is M/d/yy. the way determine the default short date is the code

https://github.com/dotnet/coreclr/blob/master/src/corefx/System.Globalization.Native/calendarData.cpp#L527

https://github.com/dotnet/coreclr/blob/master/src/corefx/System.Globalization.Native/calendarData.cpp#L281

the default short date pattern used is the first one returned from this enumeration and it looks that what ICU return for KShort

但是,它会根据这个在 .NET Core 3 中更改/修复 pull request :

I tried to use dotnet core build pack 2.1.3, it did not resolve my issue (still getting 7/6/18) for format d, could you please help me to resolve for the same. Thanks in advance

这是在 3.0 中修复的。出于应用兼容性原因,我们没有更改 2.1 行为。

关于c# - Linux 上的 .net 核心日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52524957/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com