ASP.NET MVC date format
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")) %>
精彩评论