我正在根据从我的数据库中获取的文化 (en-GB) 来格式化我的日期时间列。我正在将这些数据导出到 Excel。当我下载我的数据时,某些日期时间显示为“16/10/2013 16:34:14”(即 24 小时),这是正确的,而其他日期时间显示为“11/10/2013 12:47:01 PM” "(即 12 小时)这是错误的。对于 en-GB,日期时间格式应为“dd/MM/yyyy HH:mm:ss”。如何解决这个问题。请给我建议。提前致谢。
下面是我用来将数据导出到 Excel 的代码。
GridView gv = new GridView();
gv.DataSource = dtTemp; // Here is My data
gv.DataBind();
Response.Clear();
// 'set the response mime type for excel
string fileName = string.Empty;
fileName = "Online_Topup_Report_" + DateTime.Now.Date.ToString(DayFormat.Value.ToString().Replace("/", "-")).ToString() + ".xls";
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName + "");
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Charset = "UTF-8";
StringWriter stringWrite = new StringWriter();
// 'create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
// 'tell the datagrid to render itself to our htmltextwriter
gv.RenderControl(htmlWrite);
Response.Output.Write(stringWrite.ToString());
Response.End();