问题描述
我有两个日期按以下格式进行比较
从后端服务来响应有以下日期格式
I have two dates to be compared in the following formatthe response coming from backend service has following date format
alignFillDate - 2015-06-25
pickUpDate - 2015年5月10日
alignFillDate - 2015-06-09pickUpDate - 2015-05-10
所以,前端需要检查的条件是,如果pickUpDate少那么alignFillDate,我们将30天增加alignFillDate,也就是说,我们增加pickUpDate下个月(30天了),并显示不同的文本查看
so, front end needs to check the condition is if pickUpDate is less then the alignFillDate, we will increase the alignFillDate by 30 days, i.e, we increment the pickUpDate to next month(30 days from now ) and show different text on view
怎么,我实现这一目标采用了棱角分明和JavaScript。 ?怎么做我的html和控制器需要改变这个日期计算
How, do i achieve this using angular and javascript. ? how does my html and controller needs to changed for this date calculation
推荐答案
您保存这些日期字符串为Date对象,做香草的比较JavaScript和分配范围或本。
You save those date strings as Date objects, do a comparison with vanilla javascript and assign to scope or this.
var alignFillDate = new Date("2015-06-09");
var pickUpDate = new Date("2015-05-10");
if (pickUpDate < alignFillDate) {
alignFillDate = alignFillDate.setDate(alignFillDate.getDate() + 30);
}
$scope.pickUpDate = pickUpDate;
$scope.alignFillDate = alignFillDate;
下面是一个普拉克,做你正在尝试做的。
Here is a plunk that does what you are trying to do http://plnkr.co/edit/Kq7WA1cBcrwDyxDeBFAL?p=info.
这篇关于比较两个日期angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!