Time 两个时间段之间的代码差异

Time 两个时间段之间的代码差异,time,vb6,Time,Vb6,我需要vb6代码的帮助 我需要这样的代码 t1.text=now ' example "10:30:00 PM" t2.text="1:00:00 am" ' that next day and i can chang him t3.text=t2.text-t1.text ' he most be "2:30:00"and Countdown 'and i need code to + hour amd minute ' example 't2.text is "1:00:00" + n

我需要vb6代码的帮助 我需要这样的代码

t1.text=now ' example "10:30:00 PM"
t2.text="1:00:00 am"  ' that next day and i can chang him
t3.text=t2.text-t1.text ' he most be "2:30:00"and Countdown
'and i need code to + hour amd minute 
' example 
't2.text is "1:00:00" + new time  "1:30:00" = "2:30:00"
't3.text most be "3:00:00" and Countdown 
你能帮我plz thx吗

[编辑]

我尝试了这个代码,但效果不好 因为时间今天发短信3,第二天发短信4

Dim timein As Date
将超时设置为日期
尺寸v_差异作为日期
专用子定时器3_定时器()
text4.text=“1:00:00am”
Text3.Text=格式(时间,“HH:MM:SS-AMPM”)
timein=Text4.Text
超时=Text3.Text
v_diff=(timein-timeout)
'*********************************************
Hourdiff=小时(v_diff)
minutediff=分钟(v_diff)
seconddiff=秒(v_diff)
'*********************************************
Text5.Text=Hourdiff&“:”&minutediff&“:”&seconddiff
Label2.Caption=Text5.Text
您需要使用该函数。
您还希望将值存储在使用
dim variableName as Date
而不是文本框声明的变量中。您还需要以某种方式清理输入,这样当有人第一次输入“bob”作为时间时,您的程序不会崩溃。

字符串不是数字,您不能添加或删除它们。您需要先将它们转换为数字或日期,然后才能添加/减去它们

要添加/减去日期,最好使用DateAdd()和DateDiff()函数

要反复检查某些内容,最好使用计时器控件

请查看以下测试项目:

'1 form with
'  1 textbox        : name=Text1
'  1 textbox        : name=Text2
'  1 label          : name=Label1
'  1 command button : name=Command1
Option Explicit

Private Sub Command1_Click()
  'show difference between text1 and text2
  ShowDiff Text1.Text, Text2.Text
End Sub

Private Sub Timer1_Timer()
  'show countdown from now till text2
  ShowDiff CStr(Now), Text2.Text
End Sub

Private Sub Form_Load()
  'load some values
  Text1.Text = CStr(Now)
  Text2.Text = CStr(DateAdd("d", 1, Now))
  'configure timer to show difference every second
  With Timer1
    .Interval = 1000
    .Enabled = True
  End With 'Timer1
End Sub

Private Sub Form_Resize()
  Dim sngWidth As Single, sngHeight As Single
  sngWidth = ScaleWidth
  sngHeight = ScaleHeight / 4
  Text1.Move 0, 0, sngWidth, sngHeight
  Text2.Move 0, sngHeight, sngWidth, sngHeight
  Label1.Move 0, 2 * sngHeight, sngWidth, sngHeight
  Command1.Move 0, 3 * sngHeight, sngWidth, sngHeight
End Sub

Private Sub ShowDiff(strStart As String, strEnd As String)
  Dim datStart As Date, datEnd As Date
  Dim lngMin As Long
  Dim strDiff As String
  'convert strings to date types
  datStart = CDate(strStart)
  datEnd = CDate(strEnd)
  'calculate difference in minutes
  lngMin = DateDiff("n", datStart, datEnd)
  'hours
  strDiff = CStr(lngMin \ 60)
  'minutes
  strDiff = strDiff & ":" & Right$("0" & CStr(lngMin Mod 60), 2)
  'show difference as hours:minutes
  Label1.Caption = strDiff
End Sub
它将在Text1中以当前时间开始,在Text2中以明天的同一时间开始

单击按钮时,Text1和Text2之间的差异将显示在Label1中。。开始时始终为24:00,但您可以更改Text1和Text2以获得其他结果


计时器将每秒处理其事件,这将显示从当前时间到Text2中时间的倒计时。。每隔一秒钟,这将覆盖Label1中显示的任何内容。不要尝试添加字符串值,它有许多问题。你不能加两次就期望得到一个新的时间。您必须使用类似于
DateAdd()
函数的方法为时间添加间隔。我写代码是为了说明我想要的是你可以写完整的源代码,因为我不知道正确的公式,谢谢你注意:谷歌翻译,我的英语很差,我需要完整的源代码。我写了一些代码来说明我想要的是你可以写完整的源代码,因为我不知道正确的公式。谢谢你注意:谷歌翻译,我的英语很差,RQLS现在给了你一个更好的答案-我不会在这个问题上进一步扩展。thx就是这样,但我需要在这个代码中再加一个代码plz:Text2.Text=CStr(DateAdd(“d”,1,now))如何增加更多的小时和分钟我使用这个:Text2.Text=CStr(DateAdd(“d”,1,“2:30:00”))我明白了:text2.text=31/12/1899 02:30:00 Am你想在text2中做什么。。。有关DateAdd的更多信息,请将光标放在上面,然后按F1键:将text2拆分为2个标签(1个显示小时,1个显示分钟),或将小时和分钟存储到变量中,以便稍后在text2中显示。。。然后添加4个按钮以增加或减少这些值。。。这不应该太难,如果你失败了,请再试一次