使用全球化设置覆盖 mvc 3 中的日期格式

发布于 2024-12-17 02:29:24 字数 487 浏览 3 评论 0原文

我有一个使用 razor 的 mvc 网站,其中全球化设置为自动,并且使用客户首选的文化。

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />

我想知道是否有一种方法可以强制通过剃刀绑定的日期以特定格式显示而忽略文化?

例如,如果我有一个模型

public class someObj
{
  public DateTime someDateTime { get; set; }
}

并且我在视图中像这样绑定它:

@Model.someDateTime

我可以覆盖浏览器想要的首选区域性吗?

提前致谢。

I have a mvc website using razor where the globalization is set to auto and it is using the clients preferred culture.

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />

What I'd like to know is there a way to force a date that is being bound via razor to show in a specific format ignoring the culture?

For example if I have a model

public class someObj
{
  public DateTime someDateTime { get; set; }
}

And I bind it like so in the view:

@Model.someDateTime

Can I override the preferred culture that the browser wants?

Thanks in advance.

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

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

发布评论

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

评论(1

⒈起吃苦の倖褔 2024-12-24 02:29:24

调用 @Model.SomeDate.ToString("Some Format", new CultureInfo(...))

Call @Model.SomeDate.ToString("Some Format", new CultureInfo(...))

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