MVC3显示日期+没有格式字符串的短时间
在 MVC 中你可以这样做
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy h:mm tt}"]
这会转化为
2011年10月12日下午1:30
这对于 en-US 用户来说是正确的
,但是假设瑞典用户访问该网站 (sv-SE)
那么我想要
2011-10-12 13:30
所以我不能使用格式字符串..如果我从模型中删除格式属性,我将得到
10/12/2011 1:30:20 PM for en-US 和 2011-10-12 13:30:20 for sv-SE
如何在没有秒的情况下获得正确的格式?
In MVC you can do
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy h:mm tt}"]
This would translate to
10/12/2011 1:30 PM
Which is correct for a en-US user
But lets say a Swedish user visits the site (sv-SE)
Then I want
2011-10-12 13:30
so i cant use format string.. if i remove format attribute from the model I'll get
10/12/2011 1:30:20 PM for en-US
and
2011-10-12 13:30:20 for sv-SE
How can I get the correct format without seconds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
g
格式说明符,它是“常规日期短时间”格式说明符,它恰好是您正在寻找的格式说明符。像这样:
完整文档:http://msdn.microsoft.com/en-我们/library/az4se3k1.aspx
You can use the
g
format specifier, which is the "General date short time" format specifier, which happens to be the one you are looking for.Like this:
Full docs: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx