Repeater 时间格式化

mac2022-06-30  12

<%# Eval("AboutDate","{0:yyyy-MM-dd hh:mm:ss}")%> 个人认为最好用最灵活的

在Repeater控件中绑定的一个数据中,如:<%#DataBinder.Eval(Container.DataItem,"Title")%>由于数据库中的时间字段格式是:2005-12-16 11:52:01而我在Repeater控件中要的日期格式是:2005-12-16 只需要加上:<%#Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"PostTime")).ToShortDateString()%>就可以达到效果了!======================================================================转载以下有关日期类型格式化显示的文章以供学习:1.绑定时格式化日期方法: <ASP:BOUNDCOLUMN DATAFIELD= "JoinTime " DATAFORMATSTRING= "{0:yyyy-MM-dd} " >   <ITEMSTYLE WIDTH= "18% " > </ITEMSTYLE > </ASP:BOUNDCOLUMN > 2.数据控件如DataGrid/DataList等的件格式化日期方法: e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString(); 3.用String类转换日期显示格式: String.Format( "yyyy-MM-dd ",yourDateTime); 4.用Convert方法转换日期显示格式: Convert.ToDateTime("2005-8-23").ToString ("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //支持繁体数据库 5.直接用ToString方法转换日期显示格式: DateTime.Now.ToString("yyyyMMddhhmmss"); DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") 6.只显示年月 DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-M}") 7.显示时间所有部分,包括:年月日时分秒 <asp:BoundColumn DataField="收款时间" HeaderText="收款时间"   DataFormatString="{0:yyyy-MM-dd HH24:mm:ss}"> </asp:BoundColumn>********************************************************************************************************************************************ASP.NET GridView,DataList,Repeater日期格式显示

在Repeater控件中绑定的一个数据中,如:<%#DataBinder.Eval(Container.DataItem,"Title")%>由于数据库中的时间字段格式是:2005-12-16 11:52:01而我在Repeater控件中要的日期格式是:2005-12-16 只需要加上:<%#Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"PostTime")).ToShortDateString()%>就可以达到效果了!简化:<%#Convert.ToDateTime(Eval("intime")).ToShortDateString()%><%#Eval("PubDate","{0:yyyy-MM-dd}")%>Repeat控件自动编号代码:<%# Container.ItemIndex + 1%>如<asp:Repeater ID="rptService" runat="server"> <ItemTemplate><div class="service_box"> <p><span><%# Container.ItemIndex + 1%></span> <%#Eval("Title") %></p> <p><%#Eval("Content") %></p>/div></ItemTemplate> </asp:Repeater>

转载于:https://www.cnblogs.com/Kiss920Zz/archive/2012/10/22/2733390.html

最新回复(0)