恰好写过一个,没有小数<script> var timedate = new Date("May 1,2018"); //目标时间 var times = "五一长假"; var now = new Date(); //获取现在时间 var date = timedate.getTime() - now.getTime(); // var time = Math.floor(date / (1000 * 60 * 60 * 24)); var hours = Math.floor(date / (1000 * 60 * 60)); if(time >= 0) document.write("现在离" + times + "还有:" + time + "天"+"("+hours+"小时)"); </script>