我有一个DateTime具有日期和时间的实例。如何仅提取日期或时间?
Answers:
您可以使用Instance.ToShortDateString()的日期,
并Instance.ToShortTimeString()  的时间从同一个实例获得的日期和时间。
var currentDateTime = dateTime.Now();
var date=currentDateTime.Date;
    yourDateObj.ToShortDateString();
                    有时您想让GridView如此简单:
  <asp:GridView ID="grid" runat="server" />
您不想指定任何BoundField,只想将网格绑定到DataReader。在这种情况下,以下代码帮助我格式化了DateTime。
protected void Page_Load(object sender, EventArgs e)
{
  grid.RowDataBound += grid_RowDataBound;
  // Your DB access code here...
  // grid.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  // grid.DataBind();
}
void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType != DataControlRowType.DataRow)
    return;
  var dt = (e.Row.DataItem as DbDataRecord).GetDateTime(4);
  e.Row.Cells[4].Text = dt.ToString("dd.MM.yyyy");
}
结果显示在这里。
