Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 日期时间、错误的日期和月份_Javascript - Fatal编程技术网

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时会遇到问题