js get date x days ago code example

Example 1: javascript get current day of month

new Date().getDate();//gets day of month (1-31)

Example 2: JS get min date

let maxDate = new Date(8640000000000000);
let minDate = new Date(-8640000000000000);

console.log(new Date(maxDate.getTime()).toString());
console.log(new Date(maxDate.getTime() - 1).toString());
console.log(new Date(maxDate.getTime() + 1).toString()); // Invalid Date

console.log(new Date(minDate.getTime()).toString());
console.log(new Date(minDate.getTime() + 1).toString());
console.log(new Date(minDate.getTime() - 1).toString()); // Invalid Date