js中date内置对象
获取时间戳常用方法如下:
倒计时计算代码:
<script>
function countTime(time){
var nowTime=+new Date();
var futureTime=+new Date(time);
var times=(futureTime-nowTime)/1000;
var d=parseInt(times/60/60/24);
var h=parseInt(times/60/60%24);
var m=parseInt(times/60%60);
var s=parseInt(times%60);
return d+'天'+h+'小时'+m+'分'+s+'秒'
}
countTime('2018-9-10 18:00:00')
console.log( countTime('2021-4-23 21:00:00'));
</script>
创建日期对象的两种方法