1个回答
展开全部
Private Sub Command1_Click()
Dim a As Long, hutime As String
Randomize
Picture1.Cls
Text1 = Format(Now(), "Hh:Nn:Ss")
a = Int(Rnd * 86400 + 1) '获取随机秒数
If a > toNum(Time) Then '和现在时间进行比较
hqtime = toTime(a - toNum(Time))
Picture1.Print "今天 " & toTime(a) & vbCrLf & "距现在还有 " & Hour(hqtime) & "小时" & Minute(hqtime) & "分" & Second(hqtime) & "秒"
Else
hqtime = toTime(toNum(Time) - a)
Picture1.Print "今天 " & toTime(a) & vbCrLf & "到现在已经过了 " & Hour(hqtime) & "小时" & Minute(hqtime) & "分" & Second(hqtime) & "秒"
End If
End Sub
Function toTime(tn As Long) As String '将多少秒转换成 HH:MM:SS 格式
Dim hqhh As Integer, hqmm As Integer, hqss As Integer, b As Integer
hqhh = tn \ 3600
b = tn Mod 3600
hqmm = b \ 60
hqss = b Mod 60
toTime = hqhh & ":" & Format(hqmm, "00") & ":" & Format(hqss, "00")
End Function
Function toNum(tt As String) As Long '将时间转换成多少秒
toNum = Hour(tt) * 3600 + Minute(tt) * 60 + Second(tt)
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询