首页 > 解决方案 > 如何做这个语句的计算

问题描述

怎么做这个语句的计算

var dateTo = new Date(2019,04,03,3,15,0);
var countdown = Math.round((dateTo.getTime() - new Date().getTime()) / 1000);

标签: javascript

解决方案


这就是你想要的吗?

#// Set the date we're counting down to
    var countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();

  // Get todays date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));


  console.warn("val", days);

推荐阅读