-2

I have the following code and i can get the next day but the issue is prime example if it's the last day of the month it wont skip to the next month for example today the 31st it will go to 32

Here is the code i have got:

var objToday = new Date(),
            weekday = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
            dayOfWeek = weekday[objToday.getDay()],
            domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + "").charAt(0)))) return ""; a = parseInt((a + "").charAt(1)); return 1 == a ? "" : 2 == a ? "" : 3 == a ? "" : "" }(),
            dayOfMonth = today + ( objToday.getDate() < 10) ? '' + objToday.getDate() + domEnder : objToday.getDate() + domEnder,
            months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
            curMonth = months[objToday.getMonth()],
            nextMonth = months[objToday.getMonth() + 1],
            curYear = objToday.getFullYear(),
            curHour = objToday.getHours() > 12 ? objToday.getHours() - 12 : (objToday.getHours() < 10 ? "0" + objToday.getHours() : objToday.getHours()),
            curMinute = objToday.getMinutes() < 10 ? "0" + objToday.getMinutes() : objToday.getMinutes(),
            curSeconds = objToday.getSeconds() < 10 ? "0" + objToday.getSeconds() : objToday.getSeconds(),
            curMeridiem = objToday.getHours() > 12 ? "PM" : "AM";
var today = ab + ":" + curMinute + "." + curSeconds + curMeridiem + " " + dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear;


dayOfMonth_formatted = parseInt(dayOfMonth);

currentDay_formatted = curMonth + " " + dayOfMonth + 1 + "," + " " + curYear;
tomorrow_formatted = curMonth + " " + dayOfMonth_tomorrow + "," + " " + curYear;
Jakee
  • 1
  • 2
    Possible duplicate of [JavaScript, get date of the next day](http://stackoverflow.com/questions/23081158/javascript-get-date-of-the-next-day) – Johan Willfred Mar 31 '17 at 12:40
  • Why would you try to increment the date **after** formatting it as a string, instead of **before**? – Ken White Mar 31 '17 at 12:50
  • Possible duplicate of [Incrementing a date in JavaScript](http://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript) – Ken White Mar 31 '17 at 12:50

1 Answers1

0

I'd strongly suggest using https://momentjs.com/ , it would do nearly everything you're wanting to do and a lot cleaner, but more importantly more manageable.

moment(new Date()).add(1,'days');
Liam MacDonald
  • 301
  • 1
  • 9