Angular 将天添加到当前utc日期(单位:秒)

Angular 将天添加到当前utc日期(单位:秒),angular,Angular,我正在写一个jasmine测试,我需要操纵UTC日期。目前,我能够以我想要的格式获取UTC日期。我在测试中提到,在格式化之前,我需要通过添加的日期。它是component.GetUtcDate调用 例如2020-03-20T14:24:52.000 let todayDate: Date; let acceptanceDate: Date; let acceptanceDateUtc: string; fit('should call checkIfLastAgreement and not

我正在写一个jasmine测试,我需要操纵UTC日期。目前,我能够以我想要的格式获取UTC日期。我在测试中提到,在格式化之前,我需要通过添加的日期。它是component.GetUtcDate调用

例如2020-03-20T14:24:52.000

let todayDate: Date;
let acceptanceDate: Date;
let acceptanceDateUtc: string;


fit('should call checkIfLastAgreement and notify that its the last agreement when  is called accept is called', () => {
    todayDate = new Date();
    acceptanceDate = component.GetUtcDate(NEED TO ADD DAYS TO THE DATE HERE);
    acceptanceDateUtc = acceptanceDate.toISOString();
    acceptanceDateUtc = acceptanceDateUtc.substring( 0,  acceptanceDateUtc.length - 1);
    component.currentIndex = 0;
    component.myData = [{userAgreementId: 1}, { acceptanceWindowExpiry: acceptanceDateUtc }];
    component.agreementLength = 2;
    component.lastAgreement = true;
    component.activeBtn = 0;
    component.accept();

    expect(component.agreementsService.updateAgreement).toHaveBeenCalled();
    expect(component.lastAgreement).toBe(true);
    expect(component.endOfAgreements).toBe(true);
  });
在将日期传递给GetUtcDate方法之前,我需要添加天数。我该怎么做?。最后说,在增加5天之后,它应该显示2020-03-25T14:24:52.000

let todayDate: Date;
let acceptanceDate: Date;
let acceptanceDateUtc: string;


fit('should call checkIfLastAgreement and notify that its the last agreement when  is called accept is called', () => {
    todayDate = new Date();
    acceptanceDate = component.GetUtcDate(NEED TO ADD DAYS TO THE DATE HERE);
    acceptanceDateUtc = acceptanceDate.toISOString();
    acceptanceDateUtc = acceptanceDateUtc.substring( 0,  acceptanceDateUtc.length - 1);
    component.currentIndex = 0;
    component.myData = [{userAgreementId: 1}, { acceptanceWindowExpiry: acceptanceDateUtc }];
    component.agreementLength = 2;
    component.lastAgreement = true;
    component.activeBtn = 0;
    component.accept();

    expect(component.agreementsService.updateAgreement).toHaveBeenCalled();
    expect(component.lastAgreement).toBe(true);
    expect(component.endOfAgreements).toBe(true);
  });
组件代码

 GetUtcDate(date: Date) {
    const now_utc =  Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
    date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());

    return new Date(now_utc);
  }

我不太明白你需要什么,但如果你想在日期类型中添加天数,你只需要这样做:

const today=新日期();
const fiveNextDays=新日期(today.getFullYear()、today.getMonth()、today.getDate()+5);