1、如图:
2、js实现
export function countDown() {
var nowDate = new Date(); // 实时日期
var nextYear = new Date(nowDate.getFullYear() + 1 +'/1/1'); // 明年的一月一日
var timediff = Math.round((nextYear - nowDate) / 1000); // 时间差
var d = parseInt(timediff / 3600 / 24); // 天数
var h = parseInt(timediff / 3600 % 24); // 小时
var m = parseInt(timediff / 60 % 60); // 分钟
var s = parseInt(timediff % 60); // 秒
return {
day: d,
hosur: h,
minute: m,
second: s
};
}
3、vue模板实现:
<div>
距离明年元旦还有:
<span class="count_down">{{countDown.day}}</span> 天
<span class="count_down"> {{countDown.hosur}}</span> 时
<span class="count_down"> {{countDown.minute}}</span> 分
<span class="count_down"> {{countDown.second}}</span> 秒
</div>
<script>
import { countDown } from '../../public/js/你的js文件.js'
export default {
data() {
return {
countDown:[]
}
},
created() {
let that = this;
setInterval(()=>{
that.countDown = countDown();
},1000);//元旦倒计时
//console.log(Years());
},
}
</script>
网站运行记录
<span id="runTime"></span>
<script type="text/javascript">
function showTime(){
window.setTimeout("showTime()",1000);
let startDate = new Date("2018-12-24");
let nowDate = new Date();
let timeDiff = Math.round((nowDate- startDate)/ 1000);
let d = parseInt(timeDiff / 3600 / 24);
let h = parseInt(timeDiff / 3600 % 24);
let m = parseInt(timeDiff / 60 % 60);
let s = parseInt(timeDiff % 60);
document.getElementById("runTime").innerHTML = "本站已运行: "+d+"天"+h+"小时"+m+"分"+s+"秒";
}
showTime();
</script>
我的CSDN博客
评论 (0)