首页 > 解决方案 > 使用 dayjs 获取 beforeDate

问题描述

我们如何使用 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.

标签: javascriptcypress

解决方案


文档中:

dayjs().subtract(15, 'day');

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


推荐阅读