user1468303
user1468303

Reputation: 51

Javascript Date plus 1 day

Here's my code:

function getRightMonth(month) {
  var monthArr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
  return monthArr[month];
}   

var  setTomorrowDate = function(dtString){
    if(!dtString) return;
    var tm = new Date(dtString);
    tm.setDate(tm.getDate() + 1);
    var y = tm.getFullYear(),
        m = getRightMonth(tm.getMonth()),
        d = tm.getDate(),
        nd = (d < 10) ? "0" + d : d;          
    return y + "-" + m + "-" + nd;      
};

document.write(setTomorrowDate("2013-05-16"));

JSBIN

It simply takes a date string, sets a date and adds a day to it. MY problem is that when I'm in Windows, it adds the one day, but if I'm in Mac it doesn't.

Upvotes: 4

Views: 723

Answers (1)

Sudix
Sudix

Reputation: 640

It may be because of unsupportted date string in safari. I think this link will help you Invalid date in safari

Upvotes: 1

Related Questions