1.时间戳
var oDate = new Date();
var year = oDate.getFullYear()
/ 月份0开始 和数组一样 /
var year = oDate.getFullYear()
var month = oDate.getMonth() // 月 (从0开始)
var date = oDate.getDate() // 日
var day = oDate.getDay() //星期 (周日返回0)
var hour = oDate.getHours() //时
var minute = oDate.getMinutes() //分
var second = oDate.getSeconds() //秒
/ 获取毫秒 /
var mill = oDate.getTime()
var day = oDate.getDay()
<p id="p"></p>
<script>
/* 从此刻到2019-09-19 09:00:00剩余时间 */
setInterval(function () {
var oDate = new Date();
var playTime = new Date("2019-09-19 09:00:00").getTime()
var mill = oDate.getTime();
var gapTime = playTime - mill;
var seconds = Math.floor(gapTime / 1000);
var hours = Math.floor(seconds / 3600)
seconds = seconds % 3600;
var minutes = Math.floor(seconds / 60)
seconds = seconds % 60;
function transform(params) {
return params < 10 ? "0" + params : params;
}
var sum = transform(hours) + ":" + transform(minutes) + ":" + transform(seconds);
document.getElementById("p").innerHTML = sum;
},1000)
</script>