How do I get the current date in JavaScript, and create another date, only 24 hours before?
To get the current time just do:
var data = new Date();
to catch 24 hours before, how do you do?
How do I get the current date in JavaScript, and create another date, only 24 hours before?
To get the current time just do:
var data = new Date();
to catch 24 hours before, how do you do?
You can use .setDate
and spend one day less than the current date, so it will change the internal date of this variable to what you want:
var data = new Date();
data.setDate(data.getDate() - 1);
console.log(data);
Decrease the current date by the number of milliseconds in 24 hours.
var date = (new Date () - ((24*60*60)*1000));
console.log(new Date(date));
Through the getDate () function of the Date object you can capture the day
data = new Date();//cria o objeto
dia = data.getDate();//recupera o dia atual
console.log(dia)
so it is positively possible to manipulate the variable day as you wish.