如何更改datagridview的时间格式 [英] how to change the time formate of datagridview
问题描述
hi
晚上好
我正在Windows应用程序的c#.net中使用datagridview
以及更多关于如何将数据从excel工作表导入datadridview的信息
但总共一栏,在excelsheet中有"4:00 PM"
之类的时间
但是在datagridview中,当iam加载示例数据时,其示例与"12/30/1899 4:00 PM"
具有相同的色标
"4:00 PM"
"12/30/1899 4:00 PM"
But i need this one only "4:00 PM"
因此它也显示了默认日期,我尝试了很多,但没有用,我显示了示例代码
hi
good evening
i am using the datagridview in c#.net in windows application
and more over iam getting the data from the excel sheet into the datadridview
but in total one column , there is the time like "4:00 PM"
in excelsheet
but in the datagridview when iam loading with the sample data getting the same cloumn as "12/30/1899 4:00 PM"
"4:00 PM"
"12/30/1899 4:00 PM"
But i need this one only "4:00 PM"
so it was also showing the default date , i had tried a lot but no use i show my sample code
OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
cnCSV.Open();
OleDbCommand cmdSelect1 = new OleDbCommand(@sgh, cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter();
daCSV.SelectCommand = cmdSelect1;
DataSet ds = new DataSet();
DataTable dtCSV1 = new DataTable();
daCSV.Fill(dtCSV1);
daCSV.Fill(ds, comboBox1.SelectedItem.ToString());
daCSV = null;
cnCSV.Close();
return dtCSV1;
除了日期部分显示为多余的部分以外,其他一切都很好,请给我一个主意,在windwos应用程序的datagridview中将其更改为"4:00 PM"的时间
请给我建议
everything is working fine except that date part it as showing the extra part so please give me an idea , what to be changed to get the time as "4:00 PM" in datagridview in windwos application
please give me the suggestion fro me
推荐答案
您需要将this.daCSV.Columns["YourDateColumn"].DefaultCellStyle.Format
设置为最适合您的格式.有关详细信息,请检查以下内容: http://msdn.microsoft.com/en-us/library/f9x2790s.aspx [^ ]
问候
You need to set thethis.daCSV.Columns["YourDateColumn"].DefaultCellStyle.Format
into the format which best suits you needs. For details check this: http://msdn.microsoft.com/en-us/library/f9x2790s.aspx[^]
Regards
这篇关于如何更改datagridview的时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!