The first method is to set a template for the time display and then call the template where it needs to be displayed.
1. Under the Share folder, create a folder DisplayTemplates
2. Under the DisplayTemplates folder, create a view longdatetime.cshtml
3. Enter the code in the View longdatetime.cshtml
@model System.DateTime
@Model. Tolongdatestring () Of course, the latter sentence can also be changed to @model.toshortdatestring () or other date formats.
4, in the need to display the date of the place, by the original
@Html. displayfor (ModelItem = Item. Posttime) replaced with
@Html. displayfor (ModelItem = Item. Posttime, "Longdatetime") This completes the display conversion of the time format. Displayed by the original display (2013/8/6-13:37:33) (August 6, 2013)
The second method: Add DisplayFormat attribute above the model class.
Such as:
[Display (Name = "Release Time:")]
[DisplayFormat (dataformatstring = "{0:yyyy mm month DD day}")]
Public virtual System.DateTime posttime {get;set;}
displayed, this format is still August 6, 2013.
mvc-Processing Time format