+ 1

Timestamp??

Could someone help understand why this isn't executing correctly? The month and year values are printing correctly but the day value seems completely random at times and is never right. Can you see something I can't with my code?? let timestamp = function () { let today = new Date(); const date = (today.getMonth()+1) + '-' + today.getDay() + '-' + today.getFullYear(); const time = today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds(); const stamp = date + ' ' + time; return stamp; } console.log(timestamp());

4th Jun 2018, 3:57 AM
Donte Littlejohn
Donte Littlejohn - avatar
2 Answers
+ 3
Everything is correct except getDay() method use getDate() instead https://code.sololearn.com/Wsm5fQCzZ11B/?ref=app getDay() returns the day of the week (0-6) starting from sunday(0)
4th Jun 2018, 4:14 AM
Rohit
Rohit - avatar
+ 1
Thanks Mod. That worked perfectly! The getDay() is tricky I see. Thanks again!
4th Jun 2018, 4:21 AM
Donte Littlejohn
Donte Littlejohn - avatar