The code below modifies the date object and returns the time value of the updated date:
let d = new Date(); console.log('Today is: ' + d.toLocaleString()); d.setDate(d.getDate() - 3); console.log('3 days ago was: ' + d.toLocaleString());
In the first example you will get the current time, in the second one it will print the date you had 3 days before.
Setting the setDate to -1 will return the last day of the month:
let d = new Date(); console.log('Today is: ' + d.toLocaleString()); d.setDate(-1); console.log(d.toLocaleString());