繁体   English   中英

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

[英]How to calculate total working hour in 00:00 format?

我有一个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
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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM