JS实现距离上次刷新已过多少秒示例

时间:2021-05-26

复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///ajax/jquery/jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(function() {
// JQuery代码

var oldhh;
var oldmin;
var oldss;

$(document).ready(function() {
fillDate();
});
function fillDate(){
var date = new Date();
var yy = date.getFullYear();
var mm = date.getMonth()+1; //截取月,
var dd = date.getDate(); //截取日,
var cal = yy+"."+ mm +"."+dd;
var hh = date.getHours(); //截取小时,
var min = date.getMinutes(); //截取分钟,

var ss = date.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000; //然后,将得到的毫秒数再处理成秒
//(hh+":"+min+":"+ss);
oldhh = hh;
oldmin = min;
oldss = ss;
//alert(oldmin+":"+oldss);
}
window.setInterval(test,1000);
function test(){
var date = new Date();
var hh = date.getHours(); //截取小时,即8
var min = date.getMinutes(); //截取分钟,即34
var ss = date.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000; //然后,将得到的毫秒数再处理成秒
var betweenhh;
var betweenmin;
var betweenss;

if(ss<oldss){
betweenss = ss+60-oldss;
betweenhh = hh-oldhh;
betweenmin = (min+betweenhh*60)-1 - oldmin;


//alert("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}else{
betweenss = ss-oldss;
betweenhh = hh-oldhh;
betweenmin = (min + betweenhh*60) - oldmin;
//$("#message").html("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
//alert("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}
if(betweenmin<10){
if(betweenss<10){
$("#message").html("距离上次刷新0"+betweenmin+"分0"+betweenss+"秒");
}else{
$("#message").html("距离上次刷新0"+betweenmin+"分"+betweenss+"秒");
}

}else{
if(betweenss<10){
$("#message").html("距离上次刷新"+betweenmin+"分0"+betweenss+"秒");
}else{
$("#message").html("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}
}
}
});
function ByStateflag()
{
alert("hah");
var value = document.getElementById("stateflag").value;
alert(value);
}
</script>
</head>
<body>
<div id="message">

</div>
<select id="stateflag" name="stateflag" onchange="ByStateflag()">
<option selected value="">交易状态</option>
<option value="0">进行中</option>
<option value="1">终止交易</option>
<option value="3">买家已锁货</option>
<option value="4">买家办款</option>
<option value="5">交易完成</option>
</select>

</body>
</html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章