var myDate = new Date();
const currentYear = myDate.getFullYear().toString();
// 今天减今年的第一天(xxxx年01月01日)
const hasTimestamp = myDate - new Date(currentYear);
// 1000毫秒 * 60秒 * 60分钟* 24小时 = 86400000 一天
let hasDays = Math.ceil(hasTimestamp / 86400000);
console.log('当年的' + hasDays + '天') //今天是当年的第几天
let yearWeek = Math.ceil(hasDays/7);
console.log('今天是当年的第' + yearWeek + '周') //今天是当年的第几周
console.log('周' + myDate.getDay()) //周几
获取当天日期,输出今日是当年的第几天,第几周,周几
最新推荐文章于 2023-10-17 09:41:25 发布