获取当前日期(年月日星期)
function getDate() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var dates = date.getDate();
var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
var day = date.getDay();
return '今天是:' + year + '年' + month + '月' + dates + '日 ' + arr[day];
}
倒计时
function countDown(time) {
var nowTime = +new Date();
console.log(nowTime);
var InputTime = +new Date(time);
var times = (nowTime - InputTime) / 1000;
var d = parseInt(times / 60 / 60 / 24);
d > 10 ? '0' + d : d;
var h = parseInt(times / 60 % 60);
h > 10 ? '0' + h : h;
var m = parseInt(times / 60 % 60);
m > 10 ? '0' + m : m;
var s = parseInt(times % 60);
s > 10 ? '0' + s : s;
return d+"天"+h+"小时"+m+"分钟"+s+"秒";
}
console.log(countDown('2020-2-27 21:52:00'));