计算一个日期加一天

calculate a date plus one day

本文关键字:日期 一天 一个 计算      更新时间:2023-09-26

我需要在另一个日期后的一天获得日期。我知道:

$scope.date2.setDate($scope.date1.getDate()+1);
if   
$scope.date1 = 2015-11-27  
then 
$scope.date2 = 2015-11-28
It s ok,
but when 
$scope.date1 = 2015-12-02
 then 
 $scope.date2 = 2015-11-28 (ie tomorrow)

我不明白为什么。。。

如果有人知道。。

尝试这个高效简单纯JS

var todayDate = new Date();    
console.log(new Date().setDate(todayDate.getDate()+1));

因此您将拥有相同的Date类型对象,因此不需要使用moment.js

将moment.js用于此momentjs

var startdate = "2015-12-02";
var new_date = moment(startdate, "YYYY-MM-DD").add('days', 1);
var day = new_date.format('DD');
var month = new_date.format('MM');
var year = new_date.format('YYYY');
alert(new_date);
alert(day + '.' + month + '.' + year);