[removed] how can I increment a date string (YYYY-

2020-02-26 02:07发布

I know how to do this in php with date() and mktime() functions, but have no idea how to accomplish the same thing in javascript...

function incr_date(date_str){
    //...magic here
    return next_date_str;
}

var date_str = '2011-02-28';
console.log( incr_date(date_str) ); //want to output "2011-03-01"

is this even possible with js?

7条回答
疯言疯语
2楼-- · 2020-02-26 02:58

If you are using jQuery & jQuery UI then use the following:

var dt = $.datepicker.parseDate('yy-mm-dd', '2011-02-25');
dt.setDate(dt.getDate() + 1)
var dtNew = $.datepicker.formatDate('yy-mm-dd', dt);

You can parse and format any way you want, and most importantly you will not need a new function in your JS Library.

查看更多
登录 后发表回答