Html.TexBoxFor()中设置日期时间格式

来源:互联网 发布:淘宝手写披露函 编辑:程序博客网 时间:2024/05/29 19:45

今天碰到一个问题

使用的mysql数据库中的date类型默认的时间格式为2011-12-11 0:00:00 .但是前台显示时希望显示的是2011-12-11,因此日期显示格式需要设置。

示例如下:

 <%: Html.TextBoxFor(model => model.birth_date, new { Class = "datepicker", @Value = String.Format("{0:yyyy-MM-dd}", Model.birth_date) })%>

string.format()中的格式可以按照自己的需要定义

日期格式参照http://www.cnblogs.com/silverLee/archive/2009/11/05/1596828.html,其中有比较详细的实例。