Skip to content

Instantly share code, notes, and snippets.

@bernbecht
Last active August 29, 2015 14:16
Show Gist options
  • Save bernbecht/8af3888092dfa381a807 to your computer and use it in GitHub Desktop.
Save bernbecht/8af3888092dfa381a807 to your computer and use it in GitHub Desktop.
Calcula +30 dias a partir de um mês
var actualDate = new Date(2009,11,24);
var date = actualDate.getDate().toString();
var month = actualDate.getMonth().toString();
var year = actualDate.getFullYear().toString();
var testDate = new Date(year, month, date);
console.log("Antes");
console.log(actualDate);
console.log(testDate);
testDate.setDate(actualDate.getDate()+1);
if(testDate.getMonth() !== actualDate.getMonth()){
console.log("Ultimo dia");
var lastMonth = new Date(year, month, 1);
lastMonth.setMonth(lastMonth.getMonth()+2);
lastMonth.setDate(0);
}
else{
console.log("Nem é");
var lastMonth = new Date(year, month, date);
lastMonth.setMonth(lastMonth.getMonth()+1);
}
console.log("Depois");
console.log(actualDate);
console.log(lastMonth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment