C#如何将日期格式从mm / dd / yyyy转换为dd / mm / yyyy

时间:2018-08-28 09:17:54

标签: c# excel date date-formatting

我有一个DataGridView,其中包含一些数据,例如ID和StartDate。我必须将DataGridView导出到Excel文件中,一切都正确,但是日期不是我想要的格式。 进入DataGridView的日期为dd / mm / yyyy格式,进入Excel文件的为mm / dd / yyyy格式,我不知道为什么会发生。

private void btnExportExcel_Click(object sender, EventArgs e){
        string nomeFile = "Example " + DateTime.Now.ToString("yyyyMMdd",
                            CultureInfo.InvariantCulture) + ".xls";

        SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        saveFileDialog1.Filter = "Excel files|*.xls|Excel files|*.xlsx";
        saveFileDialog1.Title = "Save an Excel File";
        saveFileDialog1.FileName = nomeFile;

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {
            try
            {
                SL.WinControls.Helpers.UIWait(this);
                log.Info("Creation has begun: " + DateTime.Now);

                ExportExcel ILExport = new ExportExcel(m_DataSource, saveFileDialog1.FileName);

                SL.WinControls.Helpers.UIFree(this);
                log.Info("End : " + DateTime.Now);
            }
            catch (IOException ex)
            {
                UtilityManager.ShowMessage("E.0025", this);
            }
            MessageBox.Show("Excel file saved");
        }
        else
        {
            MessageBox.Show("Operation aborted by user");
        }
    }

0 个答案:

没有答案