Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datetime format global change

Rather than using something like this for datatime values:

@Html.DisplayTextFor("", String.Format("{0:MM/dd/yyyy}", Model.DOB))

Is it possible to set the format globally (e.g. in the web.config) in asp.net mvc 3.0?

like image 674
cs0815 Avatar asked Jun 15 '26 15:06

cs0815


1 Answers

Create a DisplayTemplate at Views/Shared/DisplayTemplates/DateTime.cshtml

@model DateTime

@String.Format("{0:MM/dd/yyyy}", Model))

Whenever you use @Html.DisplayFor() with a DateTime property, MVC will use this template.

like image 176
jrummell Avatar answered Jun 18 '26 01:06

jrummell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!