英国格式的 .net 4.0 中的日期格式被破坏

发布于 2024-08-29 21:38:41 字数 267 浏览 5 评论 0原文

我正在将几个站点转换为 .net 4.0,我似乎在日期区域化方面遇到问题。

此代码:

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString()

在 .net 3.5 中生成: '19/04/2010 00:00:00' 但一旦我将应用程序池更改为 4.0,它就会生成: '4/19/2010 12:00:00 AM'

我在哪里可以更改管理此问题的设置?

I'm in the process of converting a couple of sites up to .net 4.0 and I seem to have a problem with regionalisaion of dates.

This code:

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString()

In .net 3.5 produces: '19/04/2010 00:00:00'
but as soon as I change the app pool to 4.0 it produces: '4/19/2010 12:00:00 AM'

Where can I change the setting that governs this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2024-09-05 21:38:41

我不认为你可以尝试这个,但......

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString(dd/MM/yyy hh:mm:ss); 

这应该根据你需要格式化日期。

微软基本上为.net 4.0从头开始重建了很多东西……这在某些领域是一种痛苦,但在其他领域却是真正的优势。

我在另一个论坛上找到了一个人,他有一个由数千行代码组成的庞大项目,他现在必须在他的 datetime.tostring 语句中查找并替换这些代码。

最佳实践始终是您应该指定格式,否则您将得到框架决定的任何内容。

希望这有帮助。

I don't think you can try this instead though ...

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString(dd/MM/yyy hh:mm:ss); 

That should format the date as you need it.

Microsoft basically rebuilt quitea lot from the ground up for .net 4.0 ... it's a pain in some areas like this but a real advantage in others.

I sw a guy on another forum that has a huge project consisting of thousands of lines of code that he now has to go find and replace on his datetime.tostring statements.

Best practice has always been that you should specify the format anyway otherwise you get whatever the framework decides.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文