DataGridView显示Datetime字符串
http://tech.itdb.cn 本站原创 综合 编辑:
dezai 图片来源:网络
首先将 DataGridView 要是显示时间的列(比如StartTime) 设为String 类型. 将对应的DateTable对应的列也设位String类型. DataRow
首先将 DataGridView 要是显示时间的列(比如StartTime) 设为String 类型.
将对应的DateTable对应的列也设位String类型.
DataRow row = dt.NewRow();
Row["StartTime"] = DateTime.Now.ToString("HH:mm:ss fffffff");
注意秒与 秒的小数部分要用一个空格分割, 否则, 会出错. 秒的小数位数最高位7位
dt.Rows.Add(row);
//如果数据架构已更改,则为 true;如果只有值发生了更改,则为 false。
bindingSource1.ResetBindings(false);// 相当于.net1.1 的bund 方法
转回DateTime类型(也许保存到数据库里,想存为DateTime类型)
///
/// change string time to datetime type, the string time like '17:07:08 0346690'
///
/// the string time like '17:07:08 0346690'
/// if successfully convert the time, return the date time, else return the DateTime.MinValue;.
private DateTime ToDateTime(string strTime)
{
DateTime dt = DateTime.MinValue;
try
{
string[] strlist = strTime.Split(' ');
dt = Convert.ToDateTime(strlist[0]).AddTicks(Convert.ToInt32(strlist[1].PadRight(7,'0')));
}
catch
{ }
return dt;
} 本文作者:http://tech.itdb.cn 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读