每天倒计时代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每天倒计时代码相关的知识,希望对你有一定的参考价值。
倒计时,每天16:30分重新倒计时。例如:距离16:30分还有3小时2分钟2秒,每天重复。谢谢啦!
我来给你个VB的代码,两个方案
1.主要以一个窗口显示
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim ho, mi, se As Integer
Dim cho, cmi, cse
ho = Hour(Now)
mi = Minute(Now)
se = Second(Now)
cse = 60 - se
If mi > 30 Then
cmi = 89 - mi
Else
cmi = 29 - mi
End If
If ho >= 16 And mi > 30 Then
cho = 23 - (ho - 16)
ElseIf ho > 16 And mi <= 30 Then
cho = 24 - (ho - 16)
ElseIf ho <= 16 And mi <= 30 Then
cho = 16 - ho
ElseIf ho < 16 And mi > 30 Then
cho = 15 - ho
End If
Label1.Caption = "倒计时:" & cho & "小时" & cmi & "分钟" & cse & "秒"
End Sub
2.第二个方案,可直接在桌面显示数字(双击数字自动退出),可直接作为小工具使用
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" (ByVal hRgn As Long, lpRect As RECT) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Const RGN_AND = 1
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Form_Load()
Dim ffont As String
Dim MyRegion, MyRegion2 As Long
Dim MyRect As RECT
App.TaskVisible = False
ffont = "倒计时数据载入中。。。。。。"
Me.Font.Name = "华康少女文字W5(P)"
Me.FontBold = True
Me.Font.Size = 20
BeginPath hdc
TextOut hdc, 30, 30, ffont, 23
EndPath hdc
MyRegion = PathToRegion(hdc)
GetRgnBox MyRegion, MyRect
MyRegion2 = CreateRectRgnIndirect(MyRect)
CombineRgn MyRegion2, MyRegion2, MyRegion, RGN_AND
DeleteObject MyRegion
SetWindowRgn hwnd, MyRegion2, 1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
End Sub
Private Sub Form_DblClick()
Call Sleep(1000)
End
End Sub
Private Sub Timer1_Timer()
Dim ho, mi, se As Integer
Dim cho, cmi, cse
Dim ffont As String
Dim MyRegion, MyRegion2 As Long
Dim MyRect As RECT
ho = Hour(Now)
mi = Minute(Now)
se = Second(Now)
cse = 60 - se
If mi >= 30 Then
cmi = 89 - mi
Else
cmi = 29 - mi
End If
If ho >= 16 And mi >= 30 Then
cho = 23 - (ho - 16)
ElseIf ho > 16 And mi < 30 Then
cho = 24 - (ho - 16)
ElseIf ho <= 16 And mi < 30 Then
cho = 16 - ho
ElseIf ho < 16 And mi >= 30 Then
cho = 15 - ho
End If
App.TaskVisible = False
ffont = "倒计时:" & cho & "小时" & cmi & "分钟" & cse & "秒"
Me.Font.Name = "黑体"
Me.FontBold = True
Me.Font.Size = 18
BeginPath hdc
TextOut hdc, 30, 30, ffont, 23
EndPath hdc
MyRegion = PathToRegion(hdc)
GetRgnBox MyRegion, MyRect
MyRegion2 = CreateRectRgnIndirect(MyRect)
CombineRgn MyRegion2, MyRegion2, MyRegion, RGN_AND
DeleteObject MyRegion
SetWindowRgn hwnd, MyRegion2, 1
End Sub
参考技术A 也不知道lz要什么语言的代码!给你一个js的吧!不明白M 我!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>倒计时,每天16:30分重新倒计时。例如:距离16:30分还有3小时2分钟2秒,每天重复</title>
</head>
<body>
<script language=javascript>
var now = new Date();//当前时间
var isjx=0;
function GetServerTime()
var d= now.getYear()+"/"+now.getMonth()+"/"+now.getDate()+" 16:30:00";//设置每天的16.:30 为节点
var urodz = new Date(d);
now.setTime(now.getTime()+250);
days = (urodz - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if((hoursRound==0 && minutesRound==0 && secondsRound==0))//都等于0 说明过了16:30
isjx=1;
//判断今天还是明天
if(isjx==0 && (parseFloat(now.toTimeString().substr(0,2)+ now.toTimeString().substr(3,3).substr(0,2)+now.toTimeString().substr(6,7) )<=162959))
document.getElementById("time").innerHTML = "距离今天 16:30 还有"+hoursRound + "小时" + minutesRound + "分钟" + secondsRound +"秒" ;
else
document.getElementById("time").innerHTML = "距离明天 16:30 还有 "+hoursRound + "小时" + minutesRound + "分钟" + secondsRound +"秒";
setInterval("GetServerTime()",250);
</script>
<span id="time"></span>
</body>
</html>本回答被提问者采纳
求每天距下班时间倒计时JS代码
效果如3721.com页面
距 下班 还有:X小时XX分XX秒
下班回家吃什么呢?
比如每天下班为18:00
则12点显示为:距下班时间:6小时00分00秒
在18:00~8:00~之间显示:现在是下班时间
~~~急!十分感谢!
下面是网站搜到的
<script type="text/javascript">
ShowTime();
function ShowTime()
var d2 = new Date();
d2.setHours(18,0,0,0)
var d0 = new Date();
var ts = (d2-d0)
var h = Math.floor(ts/3600000);
var m = Math.floor((ts /60000) % 60 )
var s = Math.floor((ts /1000) % 60 )
document.getElementById("div1").innerHTML = ("剩"+h+"小时"+m+"分"+s+"秒");
window.setTimeout(ShowTime,1000);
</script>
不过要加
<div id="div1"></div>
</body>
不好运用
谁能改成直接document.write调用
回答者:璀璨今生 - 经理 四级 不符合题意呀!
小时倒计时:
<SCRIPT LANGUAGE="JavaScript"><!--var maxtime = 60*60 //一个小时,按秒计算,自己调整!function CountDown()if(maxtime>=0)minutes = Math.floor(maxtime/60);seconds = Math.floor(maxtime%60);msg = "距离结束还有"+minutes+"分"+seconds+"秒";document.all["timer"].innerHTML=msg;if(maxtime == 5*60) alert('注意,还有5分钟!');--maxtime;elseclearInterval(timer);alert("时间到,结束!");timer = setInterval("CountDown()",1000);//--></SCRIPT><div id="timer" style="color:red"></div>
以上是关于每天倒计时代码的主要内容,如果未能解决你的问题,请参考以下文章
Firestore限制每小时或每天读写一次,以防止用户在检查器中设置计时器