小程序
小游戏
企业微信
微信支付
扫描小程序码分享
求助大佬 为什么 我的getmonth和getday的值一直是 2/2 ?如图 getTime会改变 但是getmonth和getday不改变 我在3/26 和 3/30 分别做了测试
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
getDay 是星期几,今天星期二,返回2,没问题啊。
getMonth 月份是从0开始的,一月份是0.三月份就是2啊,也没问题啊
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
首先月份需要+1,所以3月的值为2;
其次获取日是getDate,而不是getDay(获取周几),所以周二的值为2.
const date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() let now = ([year, month, day]).map(n => n.toString()[1] ? n : `0${n}`).join("/") + " " + ([hour, minute, second]).map(n => n.toString()[1] ? n : `0${n}`).join(":") console.log(now)
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
getDay 是星期几,今天星期二,返回2,没问题啊。
getMonth 月份是从0开始的,一月份是0.三月份就是2啊,也没问题啊
首先月份需要+1,所以3月的值为2;
其次获取日是getDate,而不是getDay(获取周几),所以周二的值为2.
const date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() let now = ([year, month, day]).map(n => n.toString()[1] ? n : `0${n}`).join("/") + " " + ([hour, minute, second]).map(n => n.toString()[1] ? n : `0${n}`).join(":") console.log(now)