function add_month(date) {
y = date.getFullYear();
m = date.getMonth()+1;
d = date.getDate();
if (m > 11) {
m = 0;
y++;
}
last = (m===1 ? y & 3 || !(y%25) && y & 15 ? 28 : 29 : 30 + (m+1+((m+1)>>3)&1));
if (d > last)
d = last;
return new Date(y, m, d);
}
d = new Date('2016-01-31');
console.log(d.toLocaleDateString(), add_month(d).toLocaleDateString());