I'm trying to get the current date and tomorrow's date and yesteday's date as well in this format 2015-05-21
I've made these functions which work pretty good, but I wanna get your perspective about that, i'm not really expert in javascript, so I want to make sure that will work properly on my application.
function gettodaydate() {
var d = new Date();
var date=""+d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate();
return date;
}
function gettomorrowdate() {
var d = new Date();
var date=""+d.getFullYear()+"-"+d.getMonth()+"-"+(d.getDate()+1);
return date;
}
function getyesterdaydate() {
var d = new Date();
var date=""+d.getFullYear()+"-"+d.getMonth()+"-"+(d.getDate()-1);
return date;
}
Today's
var currentDate = new Date();
Print:
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
Then... if a day has 24 hours >> 60 minutes 60 seconds 1000 milliseconds....
var yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
var tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With