Ng bootstrap 格式化NgbDate

Ng bootstrap 格式化NgbDate,ng-bootstrap,Ng Bootstrap,我有一个使用NgbDate的日期选择器。我想用格式写出月份,连字符,年份。例如,2020年8月。我如何以这种方式格式化以下日期 effectiveDate = new NgbDate(date.year, date.month, date.day); effectiveDate = effectiveDate.month.toString() + '-' + effectiveDate.year.toString(); //并在组件的HTML中使用'date'管

我有一个使用NgbDate的日期选择器。我想用格式写出月份,连字符,年份。例如,2020年8月。我如何以这种方式格式化以下日期

effectiveDate = new NgbDate(date.year, date.month, date.day);
effectiveDate = effectiveDate.month.toString() + '-' +
                effectiveDate.year.toString();
//并在组件的HTML中使用'date'管道
jsDate |日期:“MM yyyy”

现在是选择答案的时候了(:谢谢你的帮助。
// the `effectiveDate` is of type `NgbDate`
effectiveDate = new NgbDate(date.year, date.month, date.day);
// you try to assign `string` to `NgbDate` which could work and it's very confusing
effectiveDate = effectiveDate.month.toString() + '-' +
                effectiveDate.year.toString();


// instead it's better to create a variable for string value + string interpolation will make it easy to read
const formattedDate = `${effectiveDate.month}-${effectiveDate.year}`;


// or you can convert `NgbDate` into `Date` in the controller
this.jsDate = new Date(effectiveDate.year, effectiveDate.month - 1, effectiveDate.day);