如何从数据库中检索时从C#中删除: [英] How to remove : from time in C# while retrieving from Database

查看:70
本文介绍了如何从数据库中检索时从C#中删除:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何从我从数据库中检索的时间格式中删除'':''。



我的代码:

Hi,

How do I remove '':'' from Time format that I retrieve from database.

My code:

int rowcount = dataGridView1.Rows.Count;
for (int i = 0; i < rowcount; i++)
{
    DateTime T = DateTime.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
    string time1 = T.TimeOfDay.ToString();
    sw.WriteLine(time1);
}



我的输出 - 11:30:36


My Output - 11:30:36

推荐答案

尝试使用替换方法 [ ^ ]:

Try using the Replace method[^]:
string time1 = T.TimeOfDay.ToString().Replace( ":", "" );




检查这个

string time1 = T.TimeOfDay.ToString(HHmmss)

check this
string time1 = T.TimeOfDay.ToString("HHmmss")


string time1 = T.TimeOfDay.ToString().Split(':')[0].ToString();



但是它''这样输出只有:11


but it''ll output like this only: 11


这篇关于如何从数据库中检索时从C#中删除:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆