我想在js中获取 年月日 星期几 本月多少天 第几天 改怎么写 谢谢
就是图片的效果 谢谢
4条回答 默认 最新
- 0x0007 2023-06-20 10:35关注
// 创建 Date 对象 let currentDate = new Date(); // 获取年份、月份、日期和星期几 let year = currentDate.getFullYear(); let month = currentDate.getMonth() + 1; // 注意 getMonth() 返回的是从0开始的月份,需要加上1 let date = currentDate.getDate(); let day = currentDate.getDay(); // getDay() 返回星期几的数字,0表示周日,依次类推 // 获取本月天数 let daysInMonth = new Date(year, month, 0).getDate(); // 传入年份和月份即可获取当月天数 // 获取今天是本月第几天 let dayOfMonth = currentDate.getDate(); console.log(`今天是${year}年${month}月${date}日,星期${day}`); console.log(`本月共有${daysInMonth}天`); console.log(`今天是本月第${dayOfMonth}天`);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 seatunnel 怎么配置Elasticsearch
- ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
- ¥15 (标签-MATLAB|关键词-多址)
- ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
- ¥500 52810做蓝牙接受端
- ¥15 基于PLC的三轴机械手程序
- ¥15 多址通信方式的抗噪声性能和系统容量对比
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程