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()

  1. <p id="p"></p>
  2. <script>
  3. /* 从此刻到2019-09-19 09:00:00剩余时间 */
  4. setInterval(function () {
  5. var oDate = new Date();
  6. var playTime = new Date("2019-09-19 09:00:00").getTime()
  7. var mill = oDate.getTime();
  8. var gapTime = playTime - mill;
  9. var seconds = Math.floor(gapTime / 1000);
  10. var hours = Math.floor(seconds / 3600)
  11. seconds = seconds % 3600;
  12. var minutes = Math.floor(seconds / 60)
  13. seconds = seconds % 60;
  14. function transform(params) {
  15. return params < 10 ? "0" + params : params;
  16. }
  17. var sum = transform(hours) + ":" + transform(minutes) + ":" + transform(seconds);
  18. document.getElementById("p").innerHTML = sum;
  19. },1000)
  20. </script>