获得未来五天的一系列日子失败了

时间:2016-11-04 07:46:30

标签: javascript

我正在使用时刻js使用此代码

获取未来五天的日期
frame-src

现在我试图在五天之后的//current date var cd = moment().format("DD-MM-YYYY"); //5 days into the future var nd = moment(cd, "DD-MM-YYYY").add(5, 'days').format('DD-MM-YYYY'); //get all dates from today to 5 days into the future current date之间获得一系列天数

the future date

这是演示https://jsfiddle.net/codebreaker87/z9d5Lusv/67/

代码仅生成当前日期。如何在?之间生成所有日期的数组。

2 个答案:

答案 0 :(得分:1)

如果您已经使用了momentjs,那么您似乎可以通过自己的代码将其功能加倍。

考虑以下片段:

var getDates = function( cd, nd ){
    var dates = [];
    var now = cd.clone();
    for(var i = 0; i < nd.diff(cd, 'days') ; i++){
        // format the date to any needed output format here
        dates.push(now.add(i, 'days').format("DD-MM-YYYY"));
    }
    return dates;
}

var r = getDates( moment(), moment().add(10, 'days'));

// r now contains
["04-11-2016", "05-11-2016", "07-11-2016", "10-11-2016", "14-11-2016", "19-11-2016", "25-11-2016", "02-12-2016", "10-12-2016", "19-12-2016"]

答案 1 :(得分:0)

我设法解决了这个问题

# Uninstall this incompatible version
brew uninstall readline

# Go to the local clone of homebrew-core
cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core

# Move to the homebrew-core revision that had 6.3.8
git checkout 35fed817726f61a9d40c8420582f6fde59eb5f14

# Re-install readline
brew reinstall readline

# Switch back to HEAD
git checkout master

# Pin readline so this can't happen again
brew pin readline
相关问题