Reputation:
I'm using this function to get the current datetime.
The problem is that the month and day are wrong. What could I be doing wrong?
Is there also a way to give a spacing between days and hours?
E.g.: 24/10/2019 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);
Upvotes: 0
Views: 125
Reputation: 711
Like @insertusernamehere said: getDay
returns day of the week and getMonth
starts on 0.
To get 24/10/2019 18: 50: 12: 02
| DAY/MONTH/YEAR HOUR: MINUTE: SECOND: MILLISECOND
The following works
date = `${d.getDate()}/${d.getMonth()+1}/${d.getFullYear()} ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}`;
Which returned: "24/10/2019 13:13:11:308"
Upvotes: 1