首页 > 解决方案 > 需要以角度 7 传递当前日期的最后一天

问题描述

我正在尝试以短日期格式将日期传递给我的角度应用程序中的方法,但日期必须是本月的最后一天。我怎么做

这就是我所做的

import {formatDate} from '@angular/common';

 this.allocationsComponent.getAllocationsDetails(formatDate(new Date(), 'yyyy/MM/dd', 'en'));

结果是

2019/04/02

标签: angular

解决方案


试试这个:

var today = new Date();
var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);
this.allocationsComponent.getAllocationsDetails(formatDate(lastDayOfMonth, 'yyyy/MM/dd', 'en'));

推荐阅读