<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>計時</title>
</head>
<body>
<div style="display: flex; justify-content: center; align-items: center;">
<span>從2019年6月31日至今:</span>
<span id="timeid1" style="font-size:35px"></span>天
<span id="timeid2" style="font-size:35px"></span>小時
<span id="timeid3" style="font-size:35px"></span>分
<span id="timeid4" style="font-size:35px"></span>秒
</div>
<script type="text/JAVAscript">
function loveTime() {
var the=new Date(2019,6,31)
var date = new Date() - the
var days = Math.floor(date / 1000 / 60 / 60 / 24) // 從這里開始
var daysmod = date - days * 24 *60 * 60 * 1000
var hours = Math.floor(daysmod / 1000 / 60 / 60)
var hoursmod = date - (days * 24 *60 * 60 * 1000) - (hours * 1000 * 60 * 60)
var minutes = Math.floor(hoursmod / 1000 / 60)
var minutesmod = date - (days * 24 *60 * 60 * 1000) - (hours * 1000 * 60 * 60) - (minutes * 1000 * 60)
var seconds = Math.floor(minutesmod / 1000) // 到這里結束,是將總毫秒轉化成對應天數+小時數+分鐘數+秒數的轉換方法
。。。。。。。。。。。。。
作者:Vam的金豆之路
篇幅有限更多請見擴展鏈接:
http://www.mark-to-win.com/tutorial/50926.html