ASP.NET MVC-DisplayFormat属性 [英] ASP.NET MVC - DisplayFormat attribute
问题描述
在我的模型中,我具有日期时间类型的MyDate属性。
在这种模式下,我使用DisplayFormat属性签名该属性:
In my model i've the MyDate property that has datetime type. I sign the property with the DisplayFormat attribute in this mode:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy hh:mm}")]
public DateTime MyDate { get; set; }
在我看来:
...
<%= Html.EditorFor(model => model.Evento.MyDate)%>
...
为什么财产的价值是'2011-05-03 14 :47',在我看来(进入EditorFor),我看到的是 03/05/2011 02.47?
why if the value of property is '2011-05-03 14:47', in my view (into EditorFor) i see '03/05/2011 02.47' ?
DataFormatString是正确的!
The DataFormatString is correct!
非常感谢答复
Alberto
推荐答案
除非我弄错了,否则 {0的格式字符串: dd / MM / yyyy hh:mm}
将输出为 03/05/2011 02.47
。您正在看到我希望看到的东西。
Unless I'm mistaken, the format string of {0:dd/MM/yyyy hh:mm}
will output as 03/05/2011 02.47
. You're seeing what I would expect to see.
更新:
要获得24小时表示法,可以使用 {0:dd / MM / yyyy HH:mm}
用大写字母 HH
指定小时。
UPDATE:
To get the 24 hour notation you can use {0:dd/MM/yyyy HH:mm}
with the uppercase HH
to designate the hour.
这篇关于ASP.NET MVC-DisplayFormat属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!