我正在创建一个VB类 - 员工在一个工作日内发生的单班工作时间。不会跨越午夜,总持续时间中断但没有指定时间。它有3个日期/时间选择器开始时间,结束时间,休息持续时间。我想从完成时间中扣除开始时间并减去休息时间以给出总工作时间。格式化HH:MM我在某个地方出错了,但是不能把手指放在上面,请你帮帮忙。
Dim TimeIn As Date = StartTime.Value
Dim TimeOut As Date = FinishTime.Value
Dim Break As Date = BreakPicker.Value
Dim TimeNow As Date = DateTime.Now
Dim TempTime As Date = TimeNow + Break
Dim BreakDuration As System.TimeSpan = TempTime - TimeNow
Dim diff As System.TimeSpan = TimeOut.Subtract(TimeIn)
Dim diff1 As System.TimeSpan = TimeOut - TimeIn
Dim diff2 As Integer = ((TimeOut - BreakDuration) - TimeIn).TotalMinutes
Dim diff3 As System.TimeSpan = TimeNow.Subtract(TimeOut)
If TimeOut <= TimeIn Then
MsgBox("Invalid time")
Exit Sub
End If
Dim TotMins As Integer = diff2
Dim Hours As Integer = Math.Floor(TotMins / 60)
Dim Minutes As Integer = TotMins Mod 60
HoursRequiredBox.Text = (Hours & "h : " & Minutes & "m".ToString())
答案 0 :(得分:0)
我会通过访问datepicker的属性来实现。
所以几个小时,你可以使用:
Dim hour1 As Integer = 0
Dim hour2 As Integer = 0
Dim hourTotal As Integer = 0
hour1 = datepicker1.value.hour
hour2 = datepicker2.value.hour
hourTotal = hour2 - hour1
同样如此。只需将.hour
替换为.minute