我需要帮助计算值班的迟到时间 - 但我的代码不会工作, 这个实际上不是时钟输入我把它放在例如。\
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
答案 0 :(得分:0)
您可能希望从时钟输出中减去时钟(否则您的时间间隔可能为负)。
DataGridView Cell的值是一个对象,因此在将其解析为DateTime之前可能需要一个.ToString。
设置.ToString()
Value
:
Dim clockIn = DateTime.Parse(row.Cells("clock in").Value.ToString())
Dim clockOut = DateTime.Parse(row.Cells("clock out").Value.ToString())
Dim total = clockOut - clockIn
row.Cells("total").Value = total.ToString()
如果DateTime.Parse不起作用,则必须查看DateTime.ParseExact