Reputation:
I have the following code:
<li>Reviewed: @Model.Modified</li>
and a model that looks like this:
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime? Modified { get; set; }
However when displayed then the date appears as follows:
REVIEWED: 8/1/2012 2:42:34 PM
Is there a simple way that I could change the way the date displays so it appears as just 8/1/2012 2PM ?
Upvotes: 0
Views: 67
Reputation: 33865
You can use DateTime.ToString(format)
in your view as well, to format the date the way you want.
So in your case, something like:
@Model.Modified.ToString("dd/MM/yyyy htt")
Upvotes: 2
Reputation: 1295
Try this
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy htt}")]
public DateTime? Modified { get; set; }
This website provides easy to understand information on setting date/time formats
Upvotes: -1
Reputation: 13640
You can use DisplayExtensions.DisplayFor method:
@Html.DisplayFor(model => model.Modified)
This helper works with data annotations and display templates.
Upvotes: 1