ASP.NET MVC - DisplayFormat属性

Alb*_*ini 0 .net dataformat editorfor data-annotations asp.net-mvc-2

在我的模型中,我有具有日期时间类型的MyDate属性.我在此模式下使用DisplayFormat属性对属性进行签名:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy hh:mm}")]
public DateTime MyDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

在我看来:

...
<%= Html.EditorFor(model => model.Evento.MyDate)%>
...
Run Code Online (Sandbox Code Playgroud)

为什么如果财产的价值是'2011-05-03 14:47',在我看来(进入EditorFor)我看到'03/05/2011 02.47'?

DataFormatString是正确的!

非常感谢你的回复

阿尔贝托

ata*_*ini 6

除非我弄错了,否则格式字符串{0:dd/MM/yyyy hh:mm}将输出为03/05/2011 02.47.你看到了我期望看到的东西.

更新: 要获得24小时表示法,您可以使用{0:dd/MM/yyyy HH:mm}大写字母HH来指定小时.