Kamran Khan
Kamran Khan

Reputation: 1109

How to change Time Format from 24 Hours to 12 in MVC View

I want to change my time from

06/08/2015 15:55:31

to

06/08/2015 03:55 PM

Here is my code.

<td >
 @Html.DisplayFor(modelItem =>item.Received) //Date Column
 @Html.HiddenFor(modelItem => item.Received, new { @class = "fieldName" })
</td>

Upvotes: 0

Views: 2152

Answers (2)

Ajay Kumar
Ajay Kumar

Reputation: 2061

you can use this attribute to format date as required on the Received property of your model

[DisplayFormat(DataFormatString = "{MMMM 0:dd yyyy}")]

Upvotes: 0

user3559349
user3559349

Reputation:

Decorate your property with the DisplayFormatAttribute

[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy hh:mm tt}")]
public DateTime Received { get; set; }

Upvotes: 2

Related Questions