我想根据输入和输出的时间差来获取支付的金额。 例。时间是:7:00:00 超时时间是:13:00:00 区别是6小时 并假设每小时费率为10.00,因此金额应为60.00 谢谢!我正在使用vb.net
我试图做的就是这样。
Private Const Format As String = "HH:mm:ss"
'this is the code i used to get the time in
Private Sub btnTimeIn_Click(sender As Object, e As EventArgs) Handles btnTimeIn.Click
TextboxTimeIn.Text = DateTime.Now.ToString(Format)
End Sub
'this is the time out
Private Sub btnTimeOut_Click(sender As Object, e As EventArgs) Handles btnTimeOut.Click
TextboxTimeOut.Text = DateTime.Now.ToString(Format)
'this is what is use to get the time difference
txtAmount.Text = Convert.ToDateTime(TextboxTimeOut.Text).Subtract(Convert.ToDateTime(TextboxTimeIn.Text)).ToString()
End Sub
但我不想显示时差,而是要在txtAmount中显示金额。例子
如果timeDifference <= 60mins,则 txtAmount = 10
else timeDifference> 60分钟,然后 txtAmount = 20
答案 0 :(得分:0)
您想了解三件事:
这些点只能在一行中计算,但为清楚起见,我们将一一清除它们:
'let's use some more variables to make this easier
Private Const Format As String = "HH:mm:ss"
Private checkin As DateTime
Private checkout As DateTime
Private rate As Integer = 10
'now with variables!
Private Sub btnTimeIn_Click(sender As Object, e As EventArgs) Handles btnTimeIn.Click
checkin = Now
TextboxTimeIn.Text = checkin.ToString(Format)
End Sub
Private Sub btnTimeOut_Click(sender As Object, e As EventArgs) Handles btnTimeOut.Click
checkout = Now
TextboxTimeOut.Text = checkout.ToString(Format)
'First we check for an amount of hours, then we add one if they overstayed
Dim timeStayed As Integer = checkout.Hour - checkin.Hour
If TimeStayed.Minute > 0 Then timeStayed += 1
'Notice the use of a variable so you can tweak your rates easily
txtAmount.Text = (timeStayed * rate).ToString
End Sub
这里您需要记住的是: