Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将天/小时/分钟/秒转换为小时/分钟/秒_C#_Mysql_Winforms - Fatal编程技术网

C# 将天/小时/分钟/秒转换为小时/分钟/秒

C# 将天/小时/分钟/秒转换为小时/分钟/秒,c#,mysql,winforms,C#,Mysql,Winforms,我有一个时间表应用程序,显示在给定的时间跨度内工作了多少小时。它工作完美,但当我想显示总工作小时数时,它会在工作24小时后显示此格式:1.01:06:16。我需要将其转换为以下格式:25:06:16。我搜索了,但只找到了其他转换,但没有找到我需要的转换表“timespan”是时间格式的。这是我的密码: ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["shopmanagerConnecti

我有一个时间表应用程序,显示在给定的时间跨度内工作了多少小时。它工作完美,但当我想显示总工作小时数时,它会在工作24小时后显示此格式:1.01:06:16。我需要将其转换为以下格式:25:06:16。我搜索了,但只找到了其他转换,但没有找到我需要的转换表“timespan”是时间格式的。这是我的密码:

ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["shopmanagerConnectionString1"];
        MySqlConnection con = new MySqlConnection(conSettings.ToString());
        MySqlCommand cmd = new MySqlCommand(@"select timespan as 'Temps' from shopmanager.time_sheet where project_number = @project_number and users_employee_number = @users_employee_number and week_number = @week_number;", con);    

cmd.Parameters.AddWithValue("@project_number", username.default_project);
            cmd.Parameters.AddWithValue("@users_employee_number", username.user_id);

            cmd.Parameters.AddWithValue("@week_number", GetWeekNumber());
            DataTable dt = new DataTable();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            da.Fill(dt);

            object sum;
            sum = dt.Compute("Sum(Temps)", "");
            textBox1.Text = sum.ToString();
            cmd.Parameters.Clear();
我对这件事还不熟悉,似乎不明白。如果有人能帮我,那就太好了


谢谢,我知道怎么做了。以下是最终代码:

object sum;
            sum = dt.Compute("Sum(Temps)", "");
            TimeSpan time = TimeSpan.Parse(sum.ToString());
            string timeForDisplay = (int)time.TotalHours + time.ToString(@"\:mm\:ss");
            textBox1.Text = timeForDisplay;

这非常有效。

请更改
textBox1.Text=sum.ToString();cmd.Parameters.Clear()
to
textBox1.Text=sum.ToString();var bob=sum.GetType();cmd.Parameters.Clear()
bob的值是多少?
TimeSpan.Parse可能不需要。如果您可以进行我建议的更改并检查
bob
的值,我们可以向您展示一种更好、更快的解决问题的方法。另外,通过提供这些信息,这将帮助下一个有此问题的人。好的,谢谢。我要试一试。