//日期
const now =new Date();
console.log(now) Wed May 25 2022 23:37:32 GMT+0800 (中国标准时间)
console.log(typeof now) //object
//年 月 日 时间
console.log('getFullYear:',now.getFullYear()); //年
console.log('getMonth:',now.getMonth()+1);//月
console.log('getDate:',now.getDate()); //日
console.log('getDay:',now.getDay()); //星期几 0 等于星期天
console.log('getHours:',now.getHours()); //时
console.log('getDate:',now.getMinutes()); //分
console.log('getSeconds:',now.getSeconds()); //秒
//timestamps 时间戳 1970年 1月1日 - 当下
console.log('timestamps',now.getTime());
//日期字符串
console.log(now.toDateString()); //Wed May 25 2022
console.log(now.toTimeString()); //23:48:53 GMT+0800 (中国标准时间)
console.log(now.toLocaleString()); //打印本地计算机的时间
//日期
const now =new Date();
const before=new Date('February 1 2020 21:10:30');
console.log(before.getTime(),now.getTime());
//获取相差的天数 1000毫秒= 1秒
const diff=now.getTime()-before.getTime();
console.log(diff);
//Math.round 四省五入
const mins = Math.round(diff/1000/60);
const hours=Math.round(mins/60);
const days=Math.round(hours/24);
console.log(mins,hours,days);
// 知道时间戳
const timestamps=1628882116160;
console.log(new Date(timestamps));
//创建数字时钟
//日期
const clock=document.querySelector('.clock');
const tick=()=>{
const now= new Date();
const h=now.getHours();
const m=now.getMinutes();
const s=now.getSeconds();
const html=`
<span>${h}:${m}:${s}</span>
`;
clock.innerHTML=html;
};
setInterval(tick,1000);
day.js工具