Javascript 日期时间、错误的日期和月份
我正在使用此函数获取当前日期时间 问题是月份和日期都错了。我可能做错了什么 是否有一种方法可以给出日和小时之间的间隔 例如:Javascript 日期时间、错误的日期和月份,javascript,Javascript,我正在使用此函数获取当前日期时间 问题是月份和日期都错了。我可能做错了什么 是否有一种方法可以给出日和小时之间的间隔 例如:2019年10月24日18:50:12:02 setInterval(() => { this.date = new Date().getDay() + '/' + new Date().getMonth() + '/' + new Date().getFullYear() + '' + new Date().getHours() + ':' + new Date
2019年10月24日18:50:12:02
setInterval(() => {
this.date = new Date().getDay() + '/' + new Date().getMonth() + '/' + new Date().getFullYear() + '' + new Date().getHours() + ':' + new Date().getMinutes() + ':'+ new Date☮.getSeconds()
}, 1);
就像@insertusernamehere说的:
getDay
返回一周中的第几天,getMonth
从0开始
要获得2019年10月24日18:50:12:02
|日/月/年小时:分钟:秒:毫秒
以下功能
date = `${d.getDate()}/${d.getMonth()+1}/${d.getFullYear()} ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}`;
返回:
“24/10/2019 13:13:11:308”
,我建议使用它来处理datetime。@InsertUserName在这里您是对的,但不是getDay,那又怎么样?我应该选择另一种方法吗?@pbachman我已经使用了它,并且得到了它,但是我在使用ngmodel时会遇到问题