使用 dayjs 获取 beforeDate

Zom*_*Pie 3 javascript cypress

我们如何使用 DayJs 获取当前日期之前的日期。

我知道如何获取当前日期,但我们可以从当前日期删除 15 天吗?

cy.get('input[name="day"]').should('have.value', (Cypress.dayjs().format('DD')))
cy.get('input[name="month"]').should('have.value', (Cypress.dayjs().format('MM')))
 cy.get('input[name="year"]').should('have.value', (Cypress.dayjs().format('YY'))) ```


This is my code for getting the currentDate. I would like to get 15 days before my current Date. I would have used substract if the date was one input field but here we have different placeholders for the inputs.

Run Code Online (Sandbox Code Playgroud)

pav*_*man 6

文档中:

dayjs().subtract(15, 'day');
Run Code Online (Sandbox Code Playgroud)

这里提到的可用单位就是day其中之一。