我需要帮助计算晚班时间与值班 - 时钟但我的代码将不会工作, 这实际上没有时钟输入时钟我把这只是例如。\VB.NET我可以如何计算在datagridview晚的时间
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
For Each row As DataGridViewRow In frmExcelGrid.Rows
Dim clock1 As DateTime
Dim clock2 As DateTime
Dim total As TimeSpan
clock1 = DateTime.Parse(row.Cells("clock in").Value)
clock2 = DateTime.Parse(row.Cells("clock out").Value)
total = clock1 - clock2
row.Cells("total").Value = total
Next
End Sub
究竟做总说明了什么?现在你的总数将永远是一个'负面时间',因为你正在减去之前的日期。 '10:00 - 16:00 = -6:00' '16:00-10:00 = 6' – Luke
我的问题是在我从未做过的代码中计算出来的错误。 mscorlib.dll 附加信息:字符串未被识别为有效的DateTime。“未处理的异常的类型'System.FormatException'发生在mscorlib.dll中。 –