您的位置:首页 > 其它

String.Format

2009-12-07 10:08 169 查看
1.string.format格式之:日期
代码

DateTime dt =DateTime.Now;
Label1.Text =string.Format("{0:d}",dt);//2005-11-5
Label2.Text =string.Format("{0:D}",dt);//2005年11月5日
Label3.Text =string.Format("{0:f}",dt);//2005年11月5日 14:23
Label4.Text =string.Format("{0:F}",dt);//2005年11月5日 14:23:23
Label5.Text =string.Format("{0:g}",dt);//2005-11-5 14:23
Label6.Text =string.Format("{0:G}",dt);//2005-11-5 14:23:23
Label7.Text =string.Format("{0:M}",dt);//11月5日
Label8.Text =string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT
Label9.Text =string.Format("{0:s}",dt);//2005-11-05T14:23:23
Label10.Text = string.Format("{0:t}",dt);//14:23
Label11.Text = string.Format("{0:T}",dt);//14:23:23
Label12.Text = string.Format("{0:u}",dt);//2005-11-05 14:23:23Z
Label13.Text = string.Format("{0:U}",dt);//2005年11月5日 6:23:23
Label14.Text = string.Format("{0:Y}",dt);//2005年11月
Label15.Text = string.Format("{0}",dt);//2005-11-5 14:23:23?
Label16.Text = string.Format("{0:yyyyMMddHHmmssffff}",dt); //yyyymm等可以设置,比如Label16.Text = string.Format("{0:yyyyMMdd}",dt);
绑定也适用:例:<%# string.Format("{0:yyyy.MM.dd}",Eval("sj"))%>

2.http://www.cnblogs.com/sunrack/articles/1582218.html

3.

gridview在绑定显示的各种格式 收藏
gridview在绑定显示的各种格式--

gridview列 数字、货币和日期 显示格式
形式 语法 结果 注释
数字 {0:N2} 12.36
数字 {0:N0} 13
货币 {0:c2} $12.36
货币 {0:c4} $12.3656
货币 "¥{0:N2}" ¥12.36
科学计数法 {0:E3} 1.23E+001
百分数 {0:P} 12.25% P and p present the same.
日期 {0:D} 2006年11月25日
日期 {0:d} 2006-11-25
日期 {0:f} 2006年11月25日 10:30
日期 {0:F} 2006年11月25日 10:30:00
日期 {0:s} 2006-11-26 10:30:00
时间 {0:T} 10:30:00

在设置gridview等数据绑定控件的模版列时,总要设置显示的格式,这里是我查询一些资料后统计出来的。
还有一个常规的选项是用数据库中默认的格式显示。

以下是一个例子
<asp:Label ID="Label2" runat="server" Text='<%# Eval("dtt","{0:d}") %>'></asp:Label>

转载请标明出处:http://blog.csdn.net/sendling/archive/2006/12/21/1452186.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: