C# 更改列中的日期格式
目前,我班上有一个交货日期栏,在表格中显示日期格式为2015年2月23日 我想更改表中日期的格式,使其看起来像2015年2月23日。有没有办法改变这一点C# 更改列中的日期格式,c#,asp.net,webforms,C#,Asp.net,Webforms,目前,我班上有一个交货日期栏,在表格中显示日期格式为2015年2月23日 我想更改表中日期的格式,使其看起来像2015年2月23日。有没有办法改变这一点 protected void Page_Load(object sender, EventArgs e) { // Response.Cache.SetCacheability(HttpCacheability.NoCache); errormsg.Text = ""; FutureDeliveryModel theMo
protected void Page_Load(object sender, EventArgs e)
{
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
errormsg.Text = "";
FutureDeliveryModel theModel = (FutureDeliveryModel)ViewData["FutureDelivery"];
// litSite.Text = Site.getSite();
//DataTable StockTable = (DataTable)ViewData["Future"];
DataTable StockTable = theModel.GetFuture();
DataView StockView = StockTable.DefaultView;
StringBuilder SB = new StringBuilder();
SB.Append("<table class=\"display\" id=\"dt\" style=\"align: left; width: 99%;\" ");
SB.Append("rules=\"all\" border=\"1px\" ");
SB.Append("cellspacing=\"0px\" cellpadding=\"4px\">");
SB.Append("<thead>");
SB.Append("<tr></tr>");
SB.Append("<tr style=\"background-color: Silver; color: #212121; ");
SB.Append("font-weight: bold\">");
// Header
foreach (DataColumn aColumn in StockTable.Columns)
{
SB.Append("<td>");
SB.Append(aColumn.ColumnName);
SB.Append("</td>");
}
SB.Append("</tr>");
SB.Append("</thead>");
SB.Append("<tbody>");
string Site = " ";
//detail
foreach (DataRowView aRowView in StockView)
{
int qty = 0;
int export = 0;
SB.Append("<tr>");
foreach (DataColumn aColumn in StockTable.Columns)
{
SB.Append("<td style=\"text-align: left\"");
if (aColumn.ColumnName.ToString().Equals("Site"))
{
SB.Append(">");
Site = aRowView["Site"].ToString();
SB.Append(Site);
}
else
{
if (aColumn.ColumnName.ToString().Equals("Quantity")) qty = Convert.ToInt32(aRowView["Quantity"].ToString());
if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
{
export = Convert.ToInt32(aRowView["Export Quantity"].ToString());
if (export != qty && export != 0) SB.Append(" BGCOLOR=\"#00ff00\" ");
}
SB.Append(">");
if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
{
if (export == 0)
{
SB.Append(" ");
}
else
{
SB.Append(aRowView[aColumn.ColumnName].ToString());
}
}
else
{
if (aColumn.ColumnName.ToString().Equals("Delivery Date"))
{
SB.Append(aRowView[aColumn.ColumnName].ToString().Substring(0, (aRowView[aColumn.ColumnName].ToString().IndexOf(" "))));
// SB.Append(aRowView[aColumn.ColumnName].ToString().Substring(0, 10));
}
else
{
SB.Append(aRowView[aColumn.ColumnName].ToString());
}
}
}
SB.Append("</td>");
}
SB.Append("</tr>");
}
SB.Append("</tbody>");
SB.Append("</table>");
litFutureDeliveryDetail.Text = SB.ToString();
linkBackToMainPage.NavigateUrl = ApplicationUtility.FormatURL("/Stock/Login?action=out");
linkBack.NavigateUrl = (String)Session["BACKURL"];
linkUserMaint.NavigateUrl = ApplicationUtility.FormatURL("/Stock/UserMaint");
screentitle.Text = "Future Deliveries";
if (theModel.GetErrorMessage().Trim() != "")
{
StringBuilder ES = new StringBuilder();
ES.Append("<table border=1><tr><td class=\"ErrorText\">");
ES.Append(theModel.GetErrorMessage().ToString());
ES.Append("</td></tr></table>");
errormsg.Text = ES.ToString();
}
else
{
errormsg.Text = " ";
}
}
aRowView[aColumn.ColumnName]的类型是什么,如果是DateTime,您可以使用自定义格式我设法解决了这个问题,我使用convertvarchar[DELIVERY\u DATE],20作为[DELIVERY\u DATE]。这修正了日期的格式。