I want, that my DateTimeOffset in the database outputs in the View as a normal date (for example -> 10.12.2011). But it shows the date format like this -> 10.12.2011 12:30:30 +00:00. I only want to change the dateformat in the view.
My ParticialView looks like this:
@foreach (var ShippedData in Model.ShippedData) {
<tr>
<td>@ShippedData.ReceiveDate.ToString()</td>
</tr>
}
My Model like this:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd}")]
public DateTimeOffset? ReceiveDate { get; set; }
Wrong Output: 10.12.2011 12:30:30 +00:00
Correct Output should be: 10.12.2011
Calling ToString() just returns the default formatting. You either need to use DisplayFor so that the DisplayFormat attribute will be utilized:
@Html.DisplayFor(m => ShippedData.ReceiveDate)
Or, include your desired formatting in ToString:
@ShippedData.ReceiveDate.ToString("yyyy/MM/dd")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With