如何以00:00格式计算总工时?

时间:2014-05-19 11:34:38

标签: asp.net vb.net gridview

我有一个gridview,其格式为00:00的小时,我希望计算总小时数并显示在文本框中。

更新:示例2:10 + 3:50 = 6:00

到目前为止我的男女同校:

Protected Sub grdWork_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then
        If e.Row.RowType = DataControlRowType.DataRow Then
        Dim txtHours As TextBox
        txtHours = DirectCast(e.Row.FindControl("txtHours"), TextBox)
        Dim Hours1 As String = txtHours.Text

        Dim Hours2 As String = "2:50"

        Dim TS1 As New TimeSpan(Integer.Parse(Hours1.Split(":"c)(0)), Integer.Parse(Hours1.Split(":"c)(1)), 0)

        If txtHours.Text <> "" Then
            'TotalChargeableValue = TotalChargeableValue + Convert.ToDouble(txtHours.Text)
            'Dim ts2 As TimeSpan



            'Dim TS2 As New TimeSpan(Integer.Parse(Hours2.Split(":"c)(0)), Integer.Parse(Hours2.Split(":"c)(1)), 0)


            ts2 = ts2.Add(TS1)
            'ts2 = TS1

            Session("timespan") = ts2

            'ts2 = ts2.Add(TS1)
            txtSum.Text = ts2.ToString()
            'MsgBox(TS3.ToString())

        End If
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

TimeSpan t1 = TimeSpan.Parse("23:30");
TimeSpan t2 = TimeSpan.Parse("00:40:00");
TimeSpan t3 = t1.Add(t2);
Console.WriteLine(t3); // 1.00:10:00

使用DateTime:

DateTime d1 = DateTime.Parse("23:30");
DateTime d2 = DateTime.Parse("00:40:00");
DateTime d3 = d1.Add(d2.TimeOfDay); 
Console.WriteLine(d3.TimeOfDay); // 00:10:00
相关问题