开发者

ASP.NET MVC date format

开发者 https://www.devze.com 2023-02-23 01:54 出处:网络
I have the following code: <%= Html.Encode(String.Format(\"{0:g}\", item.startDate)) %> It outputs something like 01/01/2011 00:00 but I wou开发者_如何学JAVAld to ONLY show the date and not the

I have the following code: <%= Html.Encode(String.Format("{0:g}", item.startDate)) %>

It outputs something like 01/01/2011 00:00 but I wou开发者_如何学JAVAld to ONLY show the date and not the time! How can I do this? Thanks


Try

<%= Html.Encode(String.Format("{0:d}", item.startDate)) %>


<%= item.startDate.ToShortDate() %>

The above will take into account the current Locale and format it as the locale dictates. There is also no point in using Html.Encode() since it's impossible for the output of the date function to contain anything dangerous that needs encoding.


<%= Html.Encode(item.StartDate.ToString("dd/MM/yyy")) %>
0

精彩评论

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