开发者

ASP.Net MVC 3.0 DateTime Format on View?

开发者 https://www.devze.com 2023-04-12 05:46 出处:网络
I am trying to format the DateTime to Just display just date with out time. Can any one suggest on that please?

I am trying to format the DateTime to Just display just date with out time.

Can any one suggest on that please?

@Htm开发者_开发知识库l.DisplayTextFor("", String.Format("{0:dddd, MM/dd/yyyy}", Model.DOB))


You should try @Html.Raw

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

Or you can do:

@Html.DisplayFor(m => m.DOB)

and then in your model class have this attribute on the property:

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


I found this solution to be quick and easy

 @Html.FormatValue(item.PostDate,"{0:dd-mm-yyyy}")


Conversion On View Use this one..

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

and for Conversion in ViewModel you can simply use this..

(DateTime.Now).ToShortDateString();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号