VB制作倒记时器,如何实现?
来源:百度知道 编辑:UC知道 时间:2024/05/02 11:32:42
VB制作倒记时器,运用日期函数如何实现?
在窗体上加一个Timer1, 两个标签lblDay和lblTime
你可以在Timer1的Timer事件里加上:
Dim iDayLeft As Integer
Dim timeLeft As Date
Const dateToReach As Date = #8/8/2008 8:00:00 PM# '目标日期
iDayLeft = CInt(dateToReach - Now) '取整数部分(天数)
timeLeft = CDate((dateToReach - Now) - iDayLeft) '取小数部分(时间)
lblDay.Caption = iDayLeft
lblTime.Caption = timeLeft
这样就可以了。
Date类型和Date类型相减得到的是数字,整数部分代表天数,小数部分代表时间(午夜为0,正午为0.5)。