JavaScript中的日期问题

时间:2019-03-02 21:54:59

标签: javascript jquery

我是JavaScript的新手,我正在努力寻找一种解决方案,以在我们的网站上显示以下内容:

  

在2019年4月3日星期一下午3点之前下的订单将在2019年8月8日星期五交付

我们希望将其更改为每个星期一的下个星期。

这是我目前拥有的,并且效果很好,但是我不确定是否将日期格式更改为dd/mm/yyyy

function nextweek(){
    var today = new Date();
    var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
    return nextweek;
}

Date.prototype.getNextWeekMonday = function() {
    var d = new Date(this.getTime());
    var diff = d.getDate() - d.getDay() + 1;
    if (d.getDay() == 0)
        diff -= 7;
    diff += 7; // ugly hack to get next monday instead of current one
    return new Date(d.setDate(diff));
};

Date.prototype.getNextWeekFriday = function() {
    var d = this.getNextWeekMonday();
    return new Date(d.setDate(d.getDate() + 4));
};

// You can then use it like this :

var date = new Date();

document.getElementById("testa").innerHTML = "The date next monday is "+date.getNextWeekMonday();

document.getElementById("testb").innerHTML = "The date next friday is "+date.getNextWeekFriday();
<div id="testa"></div>
<div id="testb"></div>

0 个答案:

没有答案