[jsp]代码库
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0"/>
<title>行驶中</title>
<!-- 引入 Bootstrap -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<!-- 引入自定义css -->
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet">
<!-- jQuery -->
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<!-- 包括所有已编译的插件 -->
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body class="running">
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-4 ">
<br><br><br><br><br>
<h3>使用时间</h3>
<div id="show"></div>
</div>
</div>
</div>
</body>
<script>
$(function () {
var createDate = ${createDate};
if (!createDate) {
createDate = 1488781288787;
}
var rentTime = new Date(createDate);
console.log(rentTime);
setInterval(function () {
var nowTime = new Date();
var lifeTimer = nowTime.getTime() - rentTime.getTime();
var days = Math.floor(lifeTimer / (24 * 3600 * 1000));//计算出相差天数
var dlms = lifeTimer % (24 * 3600 * 1000);//计算天数后剩余的毫秒数
var hours = Math.floor(dlms / (3600 * 1000));//计算出小时数
var hlms = dlms % (3600 * 1000);//计算小时数后剩余的毫秒数
var minutes = Math.floor(hlms / (60 * 1000));//计算相差分钟数
var mlms = hlms % (60 * 1000);//计算分钟数后剩余的毫秒数
var seconds = Math.round(mlms / 1000);//计算相差秒数
var showTime = "已使用 " + days + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒";
$("#show").text(showTime);
}, 1000);
});
</script>
</html>
by: 发表于:2017-12-26 10:40:46 顶(0) | 踩(0) 回复
??
回复评论