天天看点

使用DataBinder.Eval(Object, String, String)和string.Fromat()的时间设定DataBinder.Eval(Object, String, String)的使用string.Format(format,datatime)的使用

一、

DataBinder.Eval(Container.DataItem, "INFO_ADDTIME")  

显示时间:1/6/2010 12:00:00 AM

二、

DataBinder.Eval(Container.DataItem, "INFO_ADDTIME","{0:d}")   

显示时间:1/6/2010

三、

DataBinder.Eval(Container.DataItem, "INFO_ADDTIME","{0:yyyy-MM-dd}")  

显示时间:2010-01-06

时间格式:yyyyMMddHHmmssffff

这里MM表示月,mm表示分钟。yyyy表示年,dd表示天,ss表示秒,ffff表示毫秒

在.cs文件中我们使用如下的语句

//以 2010-2-3的格式。当格式为{0:yyyy-MM-dd}时,显示2010-02-03  

      this.lblNewsTime.Text = string.Format("{0:yyyy-M-d}", (DateTime)ds.Tables[0].Rows[0][6]);  

本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2010/03/18/2297153.html,如需转载请自行联系原作者