我有以下代码,我可以在第二天获得,但问题是最好的例子,如果它是月份的最后一天它不会跳到下个月,例如今天第31天它将会转到32
这是我得到的代码:
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;
答案 0 :(得分:0)
我强烈建议使用link,它几乎可以做你想做的所有事情,而且更清洁,但更重要的是更容易管理。
moment(new Date()).add(1,'days');