Reputation: 571
I need just the time part of DateTime - HH:mm. How can I remove the rest? Can I do it in razor View:
@Html.DisplayFor(m=>m.model.MondayStart)
or do I have to add some kind of attribute in the model?
public DateTime MondayStart { get; set; }
Upvotes: 0
Views: 789
Reputation: 10824
You can use DisplayFormat
for your property:
[DisplayFormat(DataFormatString = "{HH:mm}")]
public DateTime MondayStart { get; set; }
Or you can create a DisplayTemplate:
@model DateTime?
if (Model.HasValue)
{
@Model.ToString("HH:mm")
}
Upvotes: 0
Reputation:
Add a DisplayFormatAttribute
to your property and specify the DataFormatString
property.
[DisplayFormat(DataFormatString = "{0:HH:mm}")]
public DateTime MondayStart { get; set; }
Upvotes: 3